Jump to content

[SOLVED] ALLOW LINKS


teng84

Recommended Posts

i have this code converts the url into links  the problem is that the link also affected and it brakes the real format

$string = 'http://php.net/testing_ko.php <a href="http://php.net/testing_ko.php">Other text</a>';
$pattern = '<((?:http|ftp|https)://[^ \'"]+[A-Z0-9/]\b)>i';
echo preg_replace($pattern,'<a href="$1">$1</a>',$string);

i want this to echo like this

http://php.net/testing_ko.php  <a href="http://php.net/testing_ko.php">Other text</a>

 

any ideas?

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/80720-solved-allow-links/
Share on other sites

is this what you wanting to do?

 

<?php

$string = 'http://php.net/testing_ko.php <a href="http://php.net/testing_ko.php">Other text</a>';
$pattern = '<((?:<http|ftp|https>)://[^ \'"]+[A-Z0-9/]\b)>i';
$test = preg_replace($pattern,'<a href="$1">$1</a>',$string);
echo strip_tags($test);

?>

 

this script above produces this (without the actual link - because I cannot reproduce the strip_tags on this forum):

 

http://php.net/testing_ko.php Other text

 

Link to comment
https://forums.phpfreaks.com/topic/80720-solved-allow-links/#findComment-409455
Share on other sites

do this:

 

<?php

$string = 'http://php.net/testing_ko.php <a href="http://php.net/testing_ko.php">Other text</a>';
$pattern = '<((?:<http|ftp|https>)://[^ \'"]+[A-Z0-9/]\b)>i';
$test = preg_replace($pattern,'<a href="$1">$1</a>',$string);
$link = explode(" ",$string);
echo "<a href=\"";
echo $link[0];
echo "\">";
echo strip_tags($string);
echo "</a>\n";

?>

 

This way you get the "http://php.net/testing_ko.php" as your href and you get the "Other text" as the tags value. Test this out and see if this doesn't do what you want it to do. Otherwise your going to have to explain to me what your trying to do.

Link to comment
https://forums.phpfreaks.com/topic/80720-solved-allow-links/#findComment-409474
Share on other sites

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.