Home > Article > Backend Development > PHP matching character link address program code_PHP tutorial
Yesterday, a friend asked me whether it is possible to check whether the data submitted by the user includes super connections. If so, it will be filtered directly. Let me introduce to you how to filter the connections.
Determine whether a string contains a hyperlink
The code is as follows
|
Copy code
|
||||||||||
$str="ssdsfsdfsdfss";
{ echo "This string has a hyperlink";
} } ?>
Next we only need to filter the connection part.
|
|||||||||||
echo preg_replace("/(?<=href=)([^>]*)(?=>)/i","#", " Hello, click here to take a lookHello, click here to take a look");
?>
Regular: /(?<=href=)([^>]*)(?=>)/
(?<=exp) matches the position after exp <🎜>
(?=exp) matches the position before exp <🎜>
This regular match matches all characters <🎜> that are not “>” after href= and before “>”
Example:
Find these characters (url) and replace them with # to remove all links in the html.
Now share an example of extracting hyperlinks
|