A man familiar with regular expressions can see that he has encountered some problems. now he reads a string from the database and uses regular expressions to determine whether the string contains "" and process it as & lt; a & gt; what the tag can be clicked on is that, if the continuous "" gets stuck in a regular expression, it can only be regarded as a connection, I don't know what to do.-The level is limited... For example, "dfhakoadgdai is familiar with regular expressions.
The younger brother encountered some problems.
Read a string from the database and use a regular expression to determine whether the string contains the "http: //"
And processed as Clickable labels.
At present, the younger brother is entangled in the fact that if the continuous "http: //" gets stuck in a regular expression, it can only be regarded as a connection. I don't know how to deal with it -――
The level is limited...
For example, "http: // dfhakoadghttp: // daidgjiadpugidua"
Recognized as http: // dfhakoadg and http: // daidgjiadpugidua
Share:
------ Solution --------------------
// You do not need to use regular expressions as long as your url contains the beginning of http:
$ 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 862189375829 http://www.chinindfaasdl.comhiaohdgioas
862189375829 http://www.chinindfaasdl.comhiaohdgioas
Classified http://www.chinindfaasdwfdfsdl.com of satanfa manager card data ";
$ Str = preg_replace ('/(http :\/\/.*? \. Com)/', 'click', $ str );
Var_dump ($ str );
I don't know where you want to change it? I added a click
------ Solution --------------------
Reference:
Quote: reference:
$ Str = "ahahttp: // www. chinindfaasdl. comahahttp: // www.chinindfaasdl.com
Hahahahttp: // www.chinindfaasdl.com 862189375829 http://www.chinindfaasdl.comhiaohdgioas
862189375829 http://www.chinindfaasdl.comhiaohdgioas
Classified http://www.chinindfaasdwfdfsdl.com of satanfa manager card data ";
$ Str = preg_replace ('/(http :\/\/.*? \. Com)/', 'click', $ str );
Var_dump ($ str );
I don't know where you want to change it? I added a click
Thank you for your answers. However, if you can only filter out. com, it is not the result I want to achieve...
I feel that the pile behind http needs to filter out other things except "http: //".
At present, you cannot solve this problem perfectly.
Because there may be other strings between http and the next, and these match the url rules, the program cannot determine whether the string belongs to the previous url or the interval between the two URLs.
------ Solution --------------------
$ Str = "ahahttp: // www. chinindfaasdl. comahahttp: // www.chinindfaasdl.com
Hahahahttp: // www.chinindfaasdl.com 862189375829 http://www.chinindfaasdl.comhiaohdgioas
862189375829 http://www.chinindfaasdl.comhiaohdgioas
Classified http://www.chinindfaasdwfdfsdl.com of satanfa manager card data ";
Echo preg_replace ('# http: // [\ w \.-] + \. (com
------ Solution --------------------
Net
------ Solution --------------------
Org
------ Solution --------------------
Hk
------ Solution --------------------
Info
------ Solution --------------------
Cc
------ Solution --------------------
Edu) # s', '$ 0', $ str );