我目前正在尝试在 PHP 中执行 str_replace,这对我来说是新的。这是我当前的代码。
$postAddress = str_replace("/current-url/", "/path/to/my-news/post/", $postAddress);
<li><a href="<?php echo $postAddress; ?>" ><?php echo $post->getTitle(); ?></a></li>
但是,在上面的 URL 中,我有“我的新闻”,我想更改它,以便它输出存储在管理中的 URL。因此,我不想为每个类别执行 if 语句,而是将其作为变量输出。
这是我尝试做的:
$postAddress = str_replace("/current-url/", "/path/to/"echo $cat->getTitle() "/post/", $postAddress);
我希望这是足够的信息。任何帮助将非常感激。
我认为你必须这样做:
$postAddress = str_replace("/current-url/", "/path/to/".$cat->getTitle()."/post/", $postAddress);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)