Use the PHP function preg_match_all () to convert the URL link address in the text to HTML code.

time:13-03-26 forum:PHP tools and code
  Reloaded from http://developer.51cto.com/art/200911/165859.htm

there is such a code in the PHP language, similar to the function of the preg_match () function, called the PHP function preg_match_all (). If third parameters are used, all possible matching results will be put in. This function returns the total number of pattern matches (possibly 0), and returns False if an error occurs.

below is an example of converting the URL link address in the text to HTML code. Code 6.4 is an example of the use of PHP function preg_match_all (). The

code 6.4 turns the link address in the text to HTML

[code].Lt;? PHP
/ / / / / / / / / / / / / input: string
/ / output: string
{> {/ > / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / input Until there is a blank,
preg_match_all (.Quot; /http:\/\/?.#91; ^\s.#93; /i.quot;
, $text, $links);
/ / / / / / / / / / / / / / / / > = 40. If more than $max_size is set, it is shortened.
$len = strlen ($link_url);
if ($len.Gt; $max_size)
$link_text = {
= {> > > {/ >} / > / / / / / / / / / / > = = Uot;
.Lt; a href='$link_url'.gt; $link_texta.gt;.Quot; $text);
}
return $text; a / > / / / / > "this is a multi line text containing multiple link addresses.
welcome access to http://www.taoboor.com;
Print url2html ($str);
/ * output result
this is a multiline literal
containing multiple URL link addresses. Welcome access to.Lt; a href='http://www.taoboor.com'.gt;
http://www.taoboor.coma.gt;
* /
?.gt; [/code]

hope that everyone can fully grasp the application of this function through the example of the use of the PHP function preg_match_all () above.

prev:The 5 year old child is a cleaner in the... next:Simple application of PHP function preg_...
post comment
Notice



approved   What can you eat for 10 dollars? The...   Through a hundred years, take you to...   26 mountain parks all over Ji'nan   The young man insisted on 10 years' ...   Do you remember those "made in Ji'na...
rand   What can you eat for 10 dollars? The...   Through a hundred years, take you to...   26 mountain parks all over Ji'nan   The young man insisted on 10 years' ...   Do you remember those "made in Ji'na...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com