调用后替换特定文本值 home_url

Replace a specific text value after call home_url

我刚开始编码,无法自己解决这个问题。请帮忙。

wordpress 中的示例

<input type="text" name="old" value="<?php echo home_url(); ?>" />

打印- https://example.com

更改打印值 = http://example.net

在没有Jquery的情况下,在PHP中调用home_url后是否可以更改打印值?

谢谢!

使用str_replace内联函数;将home_url() return 的值以str_replace 作为输入,然后此函数将com 替换为net,根据需要。

<input type="text" name="old" value="<?php echo str_replace('com','net',home_url()); ?>" />

我的最终答案

<input type="text" name="old" value="
            <?php 
            $letters = array('https', 'com'); 
            $fruit   = array('http', 'net');
            $output  = str_replace($letters, $fruit, home_url());
            echo $output; ?>" style="width:600px;" />