0
所以我目前运行下面的代码:运行3 str_replace函数更有效地
$current_link = get_author_posts_url($user_id,strtolower($user_info->user_login));
$current_link = str_replace(" ", "-", $current_link);
$current_link = str_replace(".-", "-", $current_link);
$current_link = str_replace("author", "authors", $current_link);
但是我觉得这个代码可能是更有效的。因为我在同一个字符串上运行str_replace 3次。 所以我用preg_replace
最小化,像这样的代码:
$cLPatterns = array(' ', '.-');
$current_link = preg_replace($cLPatterns, '-', $current_link);
$current_link = str_replace("author", "authors", $current_link);
但有使用str_replace("author", "authors", $current_link)
为preg_replace
一部分的方式我怎样才能让这段代码最有效的。
干杯
str_replace函数需要数组作为参数 – rtfm