[英]Multiple PHP str_replace
I would like to use two str_replace in my PHP echo. 我想在我的PHP echo中使用两个str_replace。 Below is my code: it displays my Wordpress post title, and replace the |
下面是我的代码:它显示我的Wordpress帖子标题,并替换|
by a </br>
to make the title appearing on multiple lines. </br>
以使标题显示在多行上。 It works, but now I would like to add italic to few words of that same title. 它可以工作,但是现在我想在同一标题的几个单词中加上斜体。 Does anybody have an idea how to manage this? 有人知道如何管理吗?
<?php echo str_replace(' | ', '<br />', get_the_title()); ?>
Why not do something such as: 为什么不做这样的事情:
$string = str_replace([' | ', 'REPLACE_ME'], ['<br />', 'REPLACE_ME'], 'STR_TO_REPLACE');
This way you only need to call str_replace
once but you can change many input values with many output values? 这样,您只需要调用一次str_replace
,但是您可以更改许多输入值和许多输出值?
Thank you, Jeppesen, it works perfectly! 谢谢Jeppesen,它运作良好! I made a small correction, here is what solved my problem: 我做了一个小更正,这是解决我的问题的原因:
<?php
$first = str_replace(' | ', '<br />', get_the_title());
echo str_replace('°', '<i />', $first);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.