Replace a specific text value after call home_url

Viewed 26

I just started the coding and can't figure this out by myself. Plese help.

example in wordpress

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

printing- https://example.com

Change printing value = http://example.net

Is it possible to change the printing value after calling the home_url in PHP without Jquery?

Thank you!

2 Answers

Use str_replace function inline; The home_url() return value to str_replace as input, then this function replace com to net, as you need.

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

My final answer

<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;" /> 
Related