Familiar with the regular expression of the warrior look over
Little brother's having a problem.
Now read a string from the database and use regular expressions to determine if it contains an "HTTP//" string
and processed into a label clickable
At present, the younger brother Tangled is, if the continuous "HTTP//" by the regular can only be judged as a connection, do not know how to deal with the-——
The level is limited ah ...
such as "Http://dfhakoadghttp://daidgjiadpugidua"
Identified as HTTP://DFHAKOADG and Http://daidgjiadpugidua
Share to:
------Solution--------------------
Just make sure your URL contains the HTTP start, you can not use the regular:
$s = ' http://dfhakoadghttp://daidgjiadpugidua ';
$a = explode (' http://', $s);
foreach ($a as $r) {
if ($r) echo "/http $r", '
';
}
Http://dfhakoadg
Http://daidgjiadpugidua
------Solution--------------------
$str = "ahahttp://www.chinindfaasdl.comahahttp://www.chinindfaasdl.com
Hahahahttp://www.chinindfaasdl.com, 862189375829http://www.chinindfaasdl.comhiaohdgioas.
862189375829http://www.chinindfaasdl.comhiaohdgioas
Satan Law Manager card data Classification http://www.chinindfaasdwfdfsdl.com ";
$str = Preg_replace ('/(http:\/\/.*?\.com)/', ' click ', $str);
Var_dump ($STR);
Don't know where you're going to change? I added a click.
------Solution--------------------
References:
Quote: References:
$str = "ahahttp://www.chinindfaasdl.comahahttp://www.chinindfaasdl.com
Hahahahttp://www.chinindfaasdl.com, 862189375829http://www.chinindfaasdl.comhiaohdgioas.
862189375829http://www.chinindfaasdl.comhiaohdgioas
Satan Law Manager card data Classification http://www.chinindfaasdwfdfsdl.com ";
$str = Preg_replace ('/(http:\/\/.*?\.com)/', ' click ', $str);
Var_dump ($STR);
Don't know where you're going to change? I added a click
to thank the answer, but only to filter out. com is not what I want to achieve the result ...
I feel that the stack behind the HTTP filter out anything but "http
//"
It should not be a perfect solution to your problem at the moment.
Because there may be other strings between HTTP and the next, and these conform to the URL rules, the program simply cannot tell whether the string belongs to the previous URL or the interval between two URLs
------Solution--------------------
$str = "ahahttp://www.chinindfaasdl.comahahttp://www.chinindfaasdl.com
Hahahahttp://www.chinindfaasdl.com, 862189375829http://www.chinindfaasdl.comhiaohdgioas.
862189375829http://www.chinindfaasdl.comhiaohdgioas
Satan Law Manager card data Classification http://www.chinindfaasdwfdfsdl.com ";
echo preg_replace (' #http://[\w\.-]+\. ( Com
------Solution--------------------
Net
------Solution--------------------
Org
------Solution--------------------
hk
------Solution--------------------
Info
------Solution--------------------
Cc
------Solution--------------------
edu) #s ', ' $ A ', $str);