Another problem with str_replace, I would like to change the following $title data into URL by taking the $string between number in the beginning and after dash (-)
Chicago's Public Schools - $10.3M
New Jersey - $3M
Michigan: Public Health - $1M
The desire output is:
chicago-public-school
new-jersey
michigan-public-health
PHP code I am using
$title = ucwords(strtolower(strip_tags(str_replace("1: ","",$title))));
$x=1;
while($x <= 10) {
$title = ucwords(strtolower(strip_tags(str_replace("$x: ","",$title))));
$x++;
}
$link = preg_replace('/[<>()!#?:.$%\^&=+~`*é"\']/', '',$title);
$money = str_replace(" ","-",$link);
$link = explode(" - ",$link);
$link = preg_replace(" (\(.*?\))", "", $link[0]);
$amount = preg_replace(" (\(.*?\))", "", $link[1]);
$code_entities_match = array( ''s' ,'"' ,'!' ,'@' ,'#' ,'$' ,'%' ,'^' ,'&' ,'*' ,'(' ,')' ,'+' ,'{' ,'}' ,'|' ,':' ,'"' ,'<' ,'>' ,'?' ,'[' ,']' ,'' ,';' ,"'" ,',' ,'.' ,'_' ,'/' ,'*' ,'+' ,'~' ,'`' ,'=' ,' ' ,'---' ,'--','--');
$code_entities_replace = array('' ,'-' ,'-' ,'' ,'' ,'' ,'-' ,'-' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'-' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'-' ,'' ,'-' ,'-' ,'' ,'' ,'' ,'' ,'' ,'-' ,'-' ,'-','-');
$link = str_replace($code_entities_match, $code_entities_replace, $link);
$link = strtolower($link);
Unfortunately the result I got:
-chicagoamp9s-public-school
2-new-jersey
3-michigan-public-health
Anyone has a better solution for this? Thanks guys!
(the ' changed into amp9 - wonder why?)