Jump to content

Can anyone tell me how do you use foreach and ++


ted_chou12

Recommended Posts

nevermind, actually, what i want to do is to detect url in a string and replace it with codes to make it a link, I came up with this, but doesnt work properly, nothing gets changed:

//further url detection
$strings = explode(" ", $entrycontent);
foreach ($strings as $string) {
$urlresult = strpos($string, "http://");
if ($urlresult === true) {$urlresults[] = $string;}}
foreach ($urlresults as $urlstring) {
$entrycontent = str_replace($urlstring, "<a href=\"". $urlstring ."\">". $urlstring ."</a>", $entrycontent);}

Can anyone help me please, thanks

thanks orio, but now, I am have some problem with strings which are already turned to links, such as

<a href="http://test.com">Test</a>

and the code still attempts to turn it into another link which is making it a mess, so is it possible to detect if the http:// is the first part of the url:

//further url detection
$strings = explode(" ", $entrycontent);
foreach ($strings as $string) {
$urlresult = strpos($string, "http://");
if ($urlresult == 0) {$urlresults[] = $string;}}
foreach ($urlresults as $urlstring) {
$entrycontent = str_replace($urlstring, "<a href=\"". $urlstring ."\">". $urlstring ."</a>", $entrycontent);}

But this doesnt seem to help... because I saw that the manual says that the number indicates the position.

Thanks

Ted

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.