Familiar with the regular expression of the warrior look over

Source: Internet
Author: User
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);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.