I have a long string and would like to replace every dot "." with a question mark, however my string includes domain extensions such as .com which I would like to skip when replacing.
Is there any way I can provide an array such as (".com", ".net", ".org") of phrases to skip when replacing using str_replace() or a similar function?
Input sentence:
$string = "An example of a website would be google.com or similar. However this is not what we are looking for";
The following:
str_replace(".", "?", $string);
Produces:
An example of a website would be google?com or similar? However this is not what we are looking for
Desired output:
An example of a website would be google.com or similar? However this is not what we are looking for
I would like to provide an array of domain extensions to skip, when replacing. Such as:
$skip = array(".com",".net",".org");
and wherever those appear, don't substitute the dot with a question mark.
EDIT: Looks like I need to use a negative lookahead with preg_replace. However not sure how to put it all together: "look for a full stop that is NOT followed by COM or NET or ORG.