Jump to content

Need help with hyperlinks code


marketinggallery

Recommended Posts

Currently I'm using the following code, which allows a url to be clickable:

 

<?=

makeClickableLinks(str_replace(chr(13),strip_tags($rshome["article_summary"],")));?>

 

 

This is the section from the function page:

 

function makeClickableLinks($text) {

  $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','<a href="\\1" target=_blank>\\1</a>', $text);

  $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1<a href="http://\\2" target=_blank>\\2</a>', $text);

  $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $text);

  return $text;

}

 

When I type out text to include a hyperlink, such as

<a href= "http://www.mysite.com/thispage.htm">display text</a> it will NOT display the clickable link.

 

How do I modify the php/html to allow it to read the link properly?

 

Any help would be much appreciated! Thank you.

Link to comment
https://forums.phpfreaks.com/topic/101271-need-help-with-hyperlinks-code/
Share on other sites

I am typing out the full html string, since I want the clickable text to display different then the actual link.

 

I checked the code and I do have <?php at the top of the function.

 

It also has <a> and </ a> shown correctly.  Looks like the code defaulted to </url> when I posted it here...

 

If I type any url, it becomes clickable okay, just not when I type in an <a href> string like my example above.

 

Any other suggestions?

 

Have a look and try............

<?php

$l=array("www.html.com","http://www.msn.co.uk","www.fool.com","http://www.google.co.uk","http://www.yahoo.com");
foreach($l as $link){

if(PREG_MATCH("/^(http)(\:\/\/(w){3}\.)[a-zA-Z](.?)[a-zA-Z]{2,3}/",$link)){


echo "<font color='blue'>Link correct $link </font> <br><br>";

}else{

echo "<font color='red'>link incorrect $link </font><br><br>";
}

echo "<a href='$link'>$link</a><br><br>";
}
?>

RedArrow-

 

I tried your code above, no luck.

 

The site wouldn't display correctly and it didn't recognize the links shown in your example.

 

It's got to be the function string and how it's reading and interpreting the url / html data

 

Any other ideas are appreciated.  Thanks much!

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.