اذهب الي المحتوي
أوفيسنا

الردود الموصى بها

قام بنشر (معدل)

هذا  تطبيق  اخر  على الداله 

 

 

كان السؤال  هو ا 

 

لدي نص مخزن في متغير ، وهذه النص يتخلله رقم (عدد) ، فهل يمكنني استخدام الدالة preg_replace بحيث تقوم بإرجاع النص المذكور مع إضافة العدد 3 مثلا للرقم الموجود داخل النص

أو بمعنى آخر
لدي المتغير التالي
$string='khaled789ahmad';
الآن أريد من الدالة المذكورة أن تقوم بإرجاع النص التالي
khaled792ahmad
فكيف يكون ذلك
وجزاكم الله خيرا

 

 

وكان هذا هو الجواب 

 

 

$string='khaled789ahmad';

function repInt($string,$increase)
{
$pattern = '/[a-zA-Z]/';
$int = preg_replace($pattern, '', $string);
$plus = $int + $increase;
$result = preg_replace('/'.$int.'/', $plus, $string);

return $result;
}

echo repInt($string,3);

تم تعديل بواسطه زمزم

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information