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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.