Design Information module in SHONC Project PHP string manipulation and regular expression Strip_tags Preg_match

Source: Internet
Author: User
Tags php regular expression

Problem: When description content requires the value of description, the first 50 characters of the information content are selected. Information content may have pictures.

The content of the output needs to be processed at this time

PHP Regular expression processing, the content of the editor output

Take pictures only:

Preg_match ('/<\s*img\s+[^>]*?src\s*=\s* (\ ' |\ ') (. *?) \\1[^>]*?\/?\s*>/i ', $news _detail[' dnews_content '], $match);

Simplest: Only text strip_tags ($news _detail[' dnews_content ');

Remove all spaces and HTML tags (including line breaks &nbsp;)

Regular expressions remove all spaces and HTML tags (including line breaks)

Preg_replace ("/(\s|\&nbsp\;| | \XC2\XA0)/"," ", Strip_tags ($STR));

Introduction: In the WAP development, access to the content of the article when the picture is set wide and high, so that in the phone will not be less than the narrowing, how to use PHP code to filter the width of the img? Matches only Chinese without English and punctuation
$htmldescription Preg_replace Strip_tags ($news _detail[' dnews_content ']));

PHP preg_replace filter img Width high
<?PHP$str= ' ; EchoContent_strip ($str); functionContent_strip ($content) {    $content=Preg_replace('/]*src=[\ ' ")? ([^>\ ' "\s]*) [\‘"]? [^>]*>/ie ', ' wap_img (' $ ') ',$content); return $content; } functionWap_img ($url) {      return' $url. ' "width=" 100% ">"; } ?>

Design Information module in SHONC Project PHP string manipulation and regular expression Strip_tags Preg_match

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.