str_replace problem

Posted by user330840 on Stack Overflow See other posts from Stack Overflow or by user330840
Published on 2010-05-02T14:27:02Z Indexed on 2010/05/02 14:37 UTC
Read the original article Hit count: 200

Filed under:

I am trying to change title data into URL. I need to get rid off all text starting from "deadline" from the following dynamic data which I get from $title:

New York deadline May 14th, 2010 (urgent)
New Hampshire deadline May 19th, 2010
New Jersey deadline

I expect the result should be like this
new-york
new-hampshire
new-jersey

Here is the code I have tried

$newurl = strip_tags(str_replace("deadline","","$title"));
$code_entities_match = array( '&quot;' ,'!' ,'@' ,'#' ,'$' ,'%' ,'^' ,'&' ,'*' ,'(' ,')' ,'+' ,'{' ,'}' ,'|' ,':' ,'"' ,'<' ,'>' ,'?' ,'[' ,']' ,'' ,';' ,"'" ,',' ,'.' ,'_' ,'/' ,'*' ,'+' ,'~' ,'`' ,'=' ,' ' ,'---' ,'--','--');
$code_entities_replace = array('' ,'-' ,'-' ,'' ,'' ,'' ,'-' ,'-' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'-' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'-' ,'' ,'-' ,'-' ,'' ,'' ,'' ,'' ,'' ,'-' ,'-' ,'-','-');
$newtitle = str_replace($code_entities_match, $code_entities_replace, $newurl);
$urltitle = strtolower($newtitle);

Unfortunately, the results are:
new-york-deadline-may-14th-2010-urgent
new-hampshire-deadline-may-19th-2010
new-jersey-

Anyone can help?

© Stack Overflow or respective owner

Related posts about php