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
Post a Comment