Link Address in PHP filter string

Source: Internet
Author: User
Tags html tags php tutorial

The easiest way to filter links is to use the Strip_tags function of the PHP tutorial, as follows

PHP Filter HTML function: Strip_tags (string) so that you can filter out all the HTML tags.
If you want to filter out all HTML tags except the , you can write this: Strip_tags (String, "Filter all HTML tags except <p>xxx</p><b></b>,

You can write this:

strip_tags (String, "<p><b>");

The above procedure is not advisable, because it filters all the HTML, so we just filter the connection part.

<?php
echo preg_replace ("/<=href=) ([^>]*) (?=>)/I", "#", "<a href= ' www.111cn.net ' > Hello, click here to see </a>< A href= ' www.111cn.net ' > Hello, click here to see </a> ');
?>
Regular:/(? <=href=) ([^>]*) (?=>)/
(? <=exp) matches the position of the exp rear
(? =exp) match the position of the exp front
This matches all characters that are not ">" before ">" After href=
Example: <a href= ' www.111cn.net ' >

To upgrade, we only filter the links of other sites to save their own site

$str = ' <li><a href= ' http://www.111cn.net/12345s ' target= ' _blank ' > Swarovski! </a></li><li><a href=http://123.com/n.php?a=luxury& target= "_blank" > F Joe </a>< /li><li><a href= "http://mb.111cn.net/" target= "_blank" > F clothing;

$match = '/<li><ashref= ' http://[w.] "*123.com/[w]+.php?a=*[w&=]*" s+target= "_blank" > (. *) </a></li>/isu ';
Preg_match_all ($match, $str, $arr);
echo "<pre>";
Print_r ($arr [0]);
echo "</pre>";

For more details please see: http://www.111cn.net/phper/php/35063.htm

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.