EMB01
asked on
Condition Fails to Return Expected Value
The attached code snippet returns prepends "http://www.example.com" to the $url variables that don't contain "http://." Then, the script appends a "<br />" tag. For $url variables that do contain "http://," the script simply echoes the $url variable but it still get's prepended with "http://www.example.com."
If the following text represents $url:
/webpage.html
I want the script to change it to:
http://www.example.com/webpage.html
If the following text represents $url:
http://www.example.com/webpage.html
I want the script to simply echo the same:
http://www.example.com/webpage.html
Ideally, I would also like to filter out "mailto:" and similar tags from being prepended with "http://."
Thank you.
If the following text represents $url:
/webpage.html
I want the script to change it to:
http://www.example.com/webpage.html
If the following text represents $url:
http://www.example.com/webpage.html
I want the script to simply echo the same:
http://www.example.com/webpage.html
Ideally, I would also like to filter out "mailto:" and similar tags from being prepended with "http://."
Thank you.
<?php
// example...
// $url could be "/webpage.html" or "http://www.example.com/webpage.html" or even "mailto:webmaster@example.com."
// all of which should be returned accordingly
if (!strpos($url, "http://")) {
echo "http://www.example.com".$url."<br />";
} else {
echo $url."<br />";
}
ASKER
Okay, that works. What about the "mailto:" part?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, again! Two in one day for me, mostart.
Try like this:
Open in new window