الفرق بين المراجعتين ل"PHP/stripslashes"

من موسوعة حسوب
< PHP
اذهب إلى التنقل اذهب إلى البحث
(أضفت المحتوى)
 
سطر 1: سطر 1:
 
+
<noinclude>{{DISPLAYTITLE:الدالة <code>stripslashes()</code>‎ في PHP}}</noinclude>
= الدالة stripslashes()‎ في PHP =
 
 
(PHP 4, PHP 5, PHP 7)
 
(PHP 4, PHP 5, PHP 7)
  
سطر 25: سطر 24:
 
المثال 1: مثال على الدالة stripslashes()‎<syntaxhighlight lang="php">
 
المثال 1: مثال على الدالة stripslashes()‎<syntaxhighlight lang="php">
 
<?php
 
<?php
 
 
$str = "Is your name O\'reilly?";
 
$str = "Is your name O\'reilly?";
 
 
// Is your name O'reilly?
 
// Is your name O'reilly?
 
 
echo stripslashes($str);
 
echo stripslashes($str);
 
 
?>
 
?>
 
</syntaxhighlight>ملاحظة: الدالة stripslashes()‎ غير تكرارية. إذا كنت ترغب في تطبيق هذه الدالة على مصفوفة متعددة الأبعاد، فأنت بحاجة إلى استخدام دالة تكرارية.
 
</syntaxhighlight>ملاحظة: الدالة stripslashes()‎ غير تكرارية. إذا كنت ترغب في تطبيق هذه الدالة على مصفوفة متعددة الأبعاد، فأنت بحاجة إلى استخدام دالة تكرارية.
سطر 37: سطر 32:
 
المثال 2: استخدام الدالة stripslashes()‎ مع مصفوفة<syntaxhighlight lang="php">
 
المثال 2: استخدام الدالة stripslashes()‎ مع مصفوفة<syntaxhighlight lang="php">
 
<?php
 
<?php
 
 
function stripslashes_deep($value)
 
function stripslashes_deep($value)
 
 
{
 
{
 
 
   $value = is_array($value) ?
 
   $value = is_array($value) ?
 
 
               array_map('stripslashes_deep', $value) :
 
               array_map('stripslashes_deep', $value) :
 
 
               stripslashes($value);
 
               stripslashes($value);
 
 
   return $value;
 
   return $value;
 
 
}
 
}
 
 
// مثال
 
// مثال
 
 
$array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
 
$array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
 
 
$array = stripslashes_deep($array);
 
$array = stripslashes_deep($array);
 
 
// المخرجات
 
// المخرجات
 
 
print_r($array);
 
print_r($array);
 
 
?>
 
?>
</syntaxhighlight>ناتج المثال السابق:<syntaxhighlight lang="php">
+
</syntaxhighlight>ناتج المثال السابق:<syntaxhighlight lang="text">
 
Array
 
Array
 
 
(
 
(
 
 
   [0] => f'oo
 
   [0] => f'oo
 
 
   [1] => b'ar
 
   [1] => b'ar
 
 
   [2] => Array
 
   [2] => Array
 
 
       (
 
       (
 
 
           [0] => fo'o
 
           [0] => fo'o
 
 
           [1] => b'ar
 
           [1] => b'ar
 
 
       )
 
       )
 
 
)
 
)
 
</syntaxhighlight>
 
</syntaxhighlight>
سطر 91: سطر 64:
 
== مصادر ==
 
== مصادر ==
 
* [http://php.net/manual/en/function.stripslashes.php صفحة الدالة stripslashes‎ في توثيق PHP الرسمي.]
 
* [http://php.net/manual/en/function.stripslashes.php صفحة الدالة stripslashes‎ في توثيق PHP الرسمي.]
 +
[[تصنيف:PHP]]
 +
[[تصنيف:PHP Function]]
 +
[[تصنيف:PHP String]]

مراجعة 13:12، 9 أبريل 2018

(PHP 4, PHP 5, PHP 7)

تلغي الدالة stripslashes()‎ تهريب سلسلة نصية مُهرِّبة.

الوصف

string stripslashes ( string $str )

تلغي الدالة stripslashes()‎ تهريب سلسلة نصية مهرَّبة.

ملاحظة: إذا كان خيار الضبط magic_quotes_sybase مُفعّلًا، فلن تُزَال أي خطوط مائلة عكسية ولكن تستبدل اثنتين من علامات الاقتباس بواحدة بدلاً من ذلك.

مثال على استخدام الدالة stripslashes()‎ هو عندما يكون خيار الضبط magic_quotes_gpc مُفعّلًا (كان مُشَغَّلًا افتراضيًا قبل الإصدار PHP 5.4) ، ولا تدخل هذه البيانات في مكان ما (مثل قاعدة البيانات) التي تتطلب تهريب المحارف الخاصة. على سبيل المثال، إذا كنت ببساطة تُخْرِج البيانات مباشرة بصيغة HTML.

المعاملات

str

السلسلة النصية المدخلة.

القيم المعادة

تعيد الدالة stripslashes()‎ سلسلة نصية مع إزالة الخطوط المائلة العكسية. (أي ‎\'‎ ستصبح ') تحوّل الخطوط المائلة العكسية المزدوجة (\\) إلى خط مائل عكسي واحد (\).

أمثلة

المثال 1: مثال على الدالة stripslashes()‎

<?php
$str = "Is your name O\'reilly?";
// Is your name O'reilly?
echo stripslashes($str);
?>

ملاحظة: الدالة stripslashes()‎ غير تكرارية. إذا كنت ترغب في تطبيق هذه الدالة على مصفوفة متعددة الأبعاد، فأنت بحاجة إلى استخدام دالة تكرارية. المثال 2: استخدام الدالة stripslashes()‎ مع مصفوفة

<?php
function stripslashes_deep($value)
{
   $value = is_array($value) ?
               array_map('stripslashes_deep', $value) :
               stripslashes($value);
   return $value;
}
// مثال
$array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
$array = stripslashes_deep($array);
// المخرجات
print_r($array);
?>

ناتج المثال السابق:

Array
(
   [0] => f'oo
   [1] => b'ar
   [2] => Array
       (
           [0] => fo'o
           [1] => b'ar
       )
)

انظر أيضًا

  • الدالة addslashes()‎: تهريب سلسلة نصية مع استخدام الخطوط المائلة الخلفية.
  • الدالة get_magic_quotes_gpc()‎: الحصول على القيمة الحالية لخيار الضبط magic_quotes_gpc.

مصادر