PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
If you don't know how to use regular expressions, use strpos to find the second occurence of http:// and substr to remove it. I ain't gonna write it for you, that's the fun of the game
llimllib wrote:If you don't know how to use regular expressions, use strpos to find the second occurence of http:// and substr to remove it. I ain't gonna write it for you, that's the fun of the game
$url = '<a href="http://www.google.com">http://www.google.com</a>';
//find the first http://
$pos = strpos($url, 'http://');
//then the second one
$pos = strpos($url, 'http://', $pos+1);
//now cut the string up to the start of the second http://
$link = substr($url, 0, $pos);
//now take everything after the second http://
$linkEnd = substr($url, $pos+7);
//and put them back together
$url = $link . $linkEnd;
echo htmlspecialchars($url);
The regular expression solutions are more elegant, but this one will show you how to use some string functions better.