This question already has an answer here:
PHP: Properly convert addresses to clickeable links in string
(1 answer)
Closed 9 years ago.
$string1 = "You can view the full calendar at
http://www.something.org/calendar/57682117
or email: info#something.org"
$string2 = "You can view the full calendar at
www.something.org/calendar/57682117
or email: info#something.org"
This is the string(s) I have. What I need to do is convert the two urls to links that will link to a page, and then the emails will need to be converted to mailto: links.
I don't need to account for websites that are blahblah.com. They will always have one of these www. or http(s). I am terrible with regular expressions... so help will be appreciated!
$output = preg_replace('_<a href="(?!mailto:)(?!tel:)[^"]+[^>]*>(.+?)</a>_', '$1', $string1);
echo '<pre>'.print_r(htmlentities($output), true).'</pre>';
Related
This question already has answers here:
How to validate an email address in PHP
(15 answers)
Closed 7 years ago.
I have a php regular expression for email formatting. I used this code below
if ( !(preg_match('/^\w+#[\w.\-]+\.[A-Za-z]{2,3}$/', $email)) ) :
$err_email1 = "<div class = 'error'>Sorry, the email is not formatted properly</div>";
$formerrors = true;
However, it doesn't work when there is a period in the email. i.e. John.Smith#mydomain.com. It works fine with JohnSmith#mydomain.com so I know it's the second period.
How can I modify the code so it works with 2 period? I tried a number of variations but didn't have success.
If you have a good php regular expression site, I am all eyes.
Thanks
Try this
/^([a-z0-9_.-]+)#([\da-z.-]+).([a-z.]{2,6})$/
This question already has answers here:
Replace URLs in text with HTML links
(17 answers)
Closed 9 years ago.
I have a input field which user enters something. Basically when user enter an url which start with http:// https// or www. i want to store it like user's words...
I'm working with php and mysql. I think replace function is for it. But when I read about it, this function only working on all string as far as I know.
For example:
input:
Hi, how are you? Please check this link : http:// www.google.com and enjoy.
output should like below:
Hi, how are you? Please check this link : http://www.google.com and enjoy.
Try this: (I don't test this code)
$output = preg_replace("#(http://|www\.)(.*) #Uis",'$1$2', $input);
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Linkify PHP text
Hi I have a field from a database that contains http links as well as normal text.
I need to find out a way to display this information using PHP to show Text and a link when applicable.
the following is my sql query:
$sql =
"select bw_supporting_doc
from cm3rm2 with(nolock)
where number = '$id'";
the output of this sql statement is:
Please find below the link to the FSS: http://blahblack.html
I need to display the http://blahblack.html as a link at the moment it is displaying as normal text.
Thanks!
function hyperlink($text){
$text = preg_replace("#(http://)+?([.]?[a-zA-Z0-9_/-])*#", "\\0", $text);
return $text;
}
this might do the job
example usage:
$str = 'this is a random string which contains a link http://www.yahoo.com';
echo hyperlink($str);
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP: STR replace by link
i'm trying to make a website that has a chatbox or a shoutbox..
when i enter a link on the textarea, for example http://link.com/ and submit it, it appears just a plain text on the chatbox, how can i make it like facebook chat any other chat that when you enter a link it will display as a link with the underline that you can click.. and i don't know how to do it..
RegEx and preg_replace are a good start for this:
$pattern = "/http:\/\/(www\.)?([^.]+\.[^.\s]+\.?[^.\s]*)/i";
$replace = "<a href='http://\\1\\2'>http://\\1\\2</a>";
$string = preg_replace($pattern,$replace,$string);
echo $string;
The good point here is, you can type in something like:
Hello, look at my site http://www.google.de
Which will be translated into:
Hello, look at my site http://www.google.de
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Detecting a url using preg_match? without in the string
I wanting to search a string that is input by the user, for instances of http:// if one is found I want to wrap the link in the correct html,
so for example, the following could be input by a user,
Google's url is http://www.google.com,
what I want to save that as it,
Google's url is http://www.google.com
is this possible?
function make_clickable($sText) {
$sClickText = str_replace(' www.', ' http://www.', $sText);
$sClickText = preg_replace("/([\s])?(http|ftp|https)([\:\/\/])([^\s]+)/i", " $2$3$4",$sClickText);
return $sClickText;
}
Tadaa!