Ask a regular question

Source: Internet
Author: User
Original string:


  • La Belle
    courbe de


    Parfait comme
    cadeau pour votre amoureux


    NOTE
    : Laver
    à la main



  • The string after processing:

  • La Belle Courbe de

    Parfait comme cadeau pour votre amoureux

    Note:laveràla Main


  • Question:
    Ask how to write regular
    Preg_replace ();


    Reply to discussion (solution)

    $arr 1=array (' #]+> ([^< ]+) \r\n#i ', ' # ]*> #i ', ' #!--? span-->\r\n#i ');
    $arr 2=array (' $ ', '
    ', ');
    Preg_replace ($arr 1, $arr 2, $STR);

    \ r \ n is the Windows text line break, note the formatting of the corresponding text
    No environmental test, feel it yourself

    $str 1 = '



  • La Belle
    courbe de


    Parfait comme
    cadeau pour votre amoureux


    NOTE
    : Laver
    à la main

  • ';

    $reg = "/ |<\/span>|zd=\ "(. *) \" |closure_uid_235198886=\ "(. *) \"/iu ";
    $str = Preg_replace ($reg, ", $str 1);

    Var_dump ($str); exit;

    $s =<<< TXT
  • La Belle courbe de
    Parfait comme cadeau pour votre amoureux
    NOTE : Laver à la main
  • Txt;echo strip_tags ($s, '

  • ');
  • $str 1 = '
  • La Belle courbe de
    Parfait comme cadeau pour votre amoureux
    NOTE : Laver à la main
  • '; $reg = "/ |<\/span>|zd=\" (. *) \ "|closure_uid_235198886=\" (. *) \ "/iu"; $str = Preg_replace ($reg, "', $str 1); v Ar_dump ($str); exit;
  • $str 1 = '
  • La Belle courbe de
    Parfait comme cadeau pour votre amoureux
    NOTE : Laver à la main
  • '; $reg = "/ |<\/span>|zd=\" (. *) \ "|closure_uid_235198886=\" (. *) \ "/iu"; $str = Preg_replace ($reg, "', $str 1); v Ar_dump ($str); exit;


  • This one didn't take
    The redundant code inside is removed.

    $s =<<< TXT
  • La Belle courbe de
    Parfait comme cadeau pour votre amoureux
    NOTE : Laver à la main
  • Txt;echo strip_tags ($s, '

  • ');


  • Because I have HTML code before and after the $s, this just intercepts some of the strings that need to be replaced, so you can't use this method, only regular.

    $patterns = Array (
    '/ ]*>/i ',
    '/<\/span>/i ',
    '/ ]*>/i ',
    );
    $replace = Array (
    '',
    '',
    '
    ',
    );
    Echo preg_replace ($patterns, $replace, $STR);

    This is good.

  • Related Article

    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.