بسم الله الرحمن الرحيم * في هذه المقالة سنتحدث عن طريقة التعامل مع النصوص في البي اتش بي . نلاحظ انه في البي اتش بي يجب احاطة اي نص بعلامة تنصيص مزدوجة او واحدة
'I am a string in single quotes'"I am a string in double quotes"
"I am not a valid string since I have unmatching quote marks''Me neither!"
$s = "I am a 'single quote string' inside a double quote string";$s = 'I am a "double quote string" inside a single quote string';
$s = "I am a \'single quote string\' inside a double quote string";$s = 'I am a \"double quote string\" inside a single quote string';'You\'d better escape your apostrophes'
$file = "c:\windows\system.ini";echo $file; // prints c:windowssystem.ini
$file = "c:\\windows\\system.ini";echo $file; // prints c:\windows\system.ini
$head = <<<ENDH$s = 'I am a "double quote string" inside a single quote string';ENDH;
$first_name = 'Charlie';$last_name = 'Brown';$full_name = $first_name . ' ' . $last_name;
echo "foo is $foo"; // this prints: foo is 2echo 'foo is $foo'; // this prints: foo is $foo
echo "value = $foo";echo "value = $a[$i]";
echo 'value = ' . $a[$i][$j];echo 'value = ' . $this->var;
select * from users where last_name = 'O'Keefe'
select * from users where last_name = 'O\'Keefe'
$last_name = "O'Keefe";$sql = "select * from users where last_name = '" . addslashes($last_name) . "'";
$str1 = 'abc';$str2 = 'def';if (!strcmp($str1, $str2)) { // remember strcmp() returns zero if the strings are identical}if ($str1 == $str2) { // PHP can compare strings directly}if ($str1 == 'def') {}
$str = substr('abcdef', 2, 3); // cde$str = substr('abcdef', -2); // ef$str = substr('abcdef', -2, 1); // e$str = substr('abcdef', 2, -2); // cd
str = substr('abcdef', القيمة الاولى,الثانية القيمة );