Write a PHP script that removes the last word from a string

  • برمجة بي اتش بي

Write a PHP script that removes the last word from a string.

Sample string : 'The quick brown fox'

الأجوبة

<?php
$str1 = 'The quick brown fox';
echo preg_replace('/\W\w+\s*(\W*)$/', '$1', $str1)."\n";
?>

Sample Output:

The quick brown
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...