PHP automatically adds the header conversion URL as a link. Sometimes, when a user needs to enter a URL, we usually let the user omit it. after the submission is complete, the code is automatically added. if necessary, we can also, when you need to enter the URL, we usually let the user omit "http: //". after the submission is complete, the code will automatically add http ://, if necessary, we can also convert the URL into a link, similar to the functions in many web editor, the following code will implement this type of function. Let's take a look at the code that automatically adds the "http: //" header:
PHP function code that automatically adds the "http: //" header:
1
2if (! Preg_match ("/^ (http | ftp):/", $ _ POST ['URL']) {
3 $ _ POST ['URL'] = 'http: // '. $ _ POST ['URL'];
4}
5?>
PHP converts the URL string to a hyperlink. you can convert the URL string and the e-mail address string to a clickable hyperlink:
01
02 function makeClickableLinks ($ text ){
03 $ text = eregi_replace ('(f | ht) {1} tp: //) [-a-zA-Z0-9 @: % _ + .~ #? & // =] + )',
04 '\ 1', $ text );
05 $ text = eregi_replace ('([[: space:] () [{}]) (www. [-a-zA-Z0-9 @: % _ + .~ #? & // =] + )',
06 '\ 1 \ 2', $ text );
07 $ text = eregi_replace ('([_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] +.) + [a-z] {2, 3 })',
08 '\ 1', $ text );
09 return $ text;
10}
11?>
By combining the two codes, you can use the following code:
View sourceprint? 1
2 $ _ POST ['URL'] = "www.codefans.net ";
3if (! Preg_match ("/^ (http | ftp):/", $ _ POST ['URL']) {
4 $ url = 'http: // '. $ _ POST ['URL'];
5}
6 echo makeClickableLinks ($ url );
7?>
The final effect is to add http: // to www.codefans.net and implement the link form.
...