Question:I am working on a multilingual wordpress website where I need to append a loclale in all internal url in a web page.
So I have all of the content of the webpage in the $content variable. now
$arrhas only those urls which needs to be appended with a locale but my str_replace is appending all urls that we have in matches array.
Answer:When you replace
www.example.com/us, it will replace it anywhere it appears, even if there’s already
You can use a regular expression with a negative lookahead to replace a string only if it’s not followed by some other pattern.
/us/, and will replace it with
If you have better answer, please add a comment about this, thank you!