php - remove unnecessary words from string -


i want remove words string make image alt tag more relevant.

the problem is, if have phase this:

barack obama @ restaurant in venice 

i want exit be:

barack obama restaurant venice 

but had is:

barack obamaa restaurantvenice 

code:-

$a = array( ' @ ', ' in ', ' arriving ', ' ', ' leaving ', ' walks ', ' walking ', ' ' ); $str = 'barack obama @ restaurant in venice'; echo str_replace($a,"",$str); 

if use words without space in array result horrible:

brck obm resturnt venice 

any ideas?

you have add 1 space inside ""like below:-

echo str_replace($a," ",$str); 

check here:-

<?php  $a = array( ' @ ', ' in ', ' arriving ', ' ', ' leaving ', ' walks ', ' walking ', ' ' ); $str = 'barack obama @ restaurant in venice'; echo str_replace($a," ",$str); 

output:-https://eval.in/636890


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -