Friday, September 9, 2022
HomeWordPress Developmentphp - How can I add a trailing slash to every str_replace...

php – How can I add a trailing slash to every str_replace outcome?


I would like to regulate some urls on my web site.

Presently, the urls are like:

mysite.com?query-7e9a-page=2
mysite.com?query-7e9a-page=3
mysite.com?query-7e9a-page=4

I would like to alter them to:

mysite.com/web page/2/
mysite.com/web page/3/
mysite.com/web page/4/

I can virtually get there with this snippet:

operate replace_text($textual content) {
    $textual content = str_replace('?query-7e9a-page=", "/web page/', $textual content);
    return $textual content;
}
add_filter('the_content', 'replace_text');

however I would like a trailing slash on the finish of the url.

I assumed I may do that:

$textual content = str_replace('?query-7e9a-page=", "/web page/', $textual content)."https://wordpress.stackexchange.com/"; //trailing slash added

however that, and each different stab at this I’ve tried, simply provides the slash to the tip of the_content. I assume that is sensible, str_replace is processing your entire textual content string after which including the /.

Is there a special php operate I ought to be utilizing?

Any solutions on how I can do that effectively?

Thanks forward of time, I have never been in a position to noodle this out,

Chris

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments