另一个问题str_replace
,我想将以下$title
数据更改为 URL,方法是$string
在开头和破折号 (-) 之后取中间数字
- 芝加哥
'
公立学校- 1030 万美元 - 新泽西州- 300 万美元
- 密歇根州:公共卫生- 100 万美元
愿望输出是:
芝加哥-公立-学校
-新泽西
-密歇根-公共卫生
我正在使用的 PHP 代码
$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);
不幸的是我得到的结果:
-chicagoamp9s-public-school
2-new-jersey
3-michigan-public-health
有人对此有更好的解决方案吗?多谢你们!
(更改为'
amp9 - 想知道为什么?)