admin管理员组文章数量:1296912
I am trying to replace the a URL of the content with php. i tried the code mentioned below but it didn't work. is there any way to achieve this with php only?
function replace_text_wps($text){
$replace = array(
';>' => ';>',
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter('the_content', 'replace_text_wps',99);
I am trying to replace the a URL of the content with php. i tried the code mentioned below but it didn't work. is there any way to achieve this with php only?
function replace_text_wps($text){
$replace = array(
'https://www.facebook/something">' => 'https://www.instagram/something">',
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter('the_content', 'replace_text_wps',99);
Share
Improve this question
asked Apr 14, 2021 at 9:18
UzairUzair
12 bronze badges
7
|
Show 2 more comments
1 Answer
Reset to default 1If you give a look at the documentation, of str_replace
you will find your needs. https://www.php/manual/en/function.str-replace.php
There is 3 choices for you there :
function replace_text_wps($text){
$replace = array(
'https://www.facebook/something">' => 'https://www.instagram/something">',
);
$text = str_replace(array_keys($replace), array_values($replace), $text);
// OR
$text = str_replace(array(
'https://www.facebook/something">'
), array(
'https://www.instagram/something">'
), $text);
// OR
$text = str_replace('https://www.facebook/something">', 'https://www.instagram/something">', $text);
return $text;
}
add_filter('the_content', 'replace_text_wps',99, 1);
本文标签: phpstrreplace with thecontent is not working
版权声明:本文标题:php - str_replace with the_content is not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741616223a2388540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$text = str_replace(array_keys($replace), array_values($replace), $text);
work? – kero Commented Apr 14, 2021 at 9:46str_replace
with arrays, you should ask this on stackoverflow instead, and it can be simplified to just the inside of the function – Tom J Nowell ♦ Commented Apr 14, 2021 at 10:07$text
, does the string you search for appear in there? – kero Commented Apr 14, 2021 at 12:05