how to cut a certain group of words in a string?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Jung

    #1

    how to cut a certain group of words in a string?

    Hello there,

    how to cut a certain group of words in a string, for example,
    "<img src='images/smiles/grin.gif' smilietext=':gr in:' border='0'
    style='vertical-align:middle' alt=':grin:' title=':grin:' />"
    "<img src='images/smiles/smile.gif' smilietext=': smile:' border='0'
    style='vertical-align:middle' alt=': smile:' title=': smile:' />"
    ¡­..
    from a forum comment.

    I tried this:
    $subject =$row_Recordset 2['pagetext']
    $pattern="/<img src='images\/smiles\/[a-zA-Z]+\.gif' smilietext=':[a-zA-Z]:'
    border='0' style='vertical-align:middle' alt=':[a-zA-Z]:' title=':[a-zA-Z]:'
    \/>/";
    $result = preg_replace($p attern,"",$subj ect);
    But I failed, I am new to PHP, please help. Thanks very much in advance.

    logically, is it a better way to search for all what is inside the <img ...
    /tag (including numbers) and replace them with ""?
    I will write: $pattern="/<img [a-zA-Z][0-9]>\/>/", is it correct? Thank you
    for your help.


  • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

    #2
    Re: how to cut a certain group of words in a string?

    Paul Jung escribió:
    how to cut a certain group of words in a string, for example,
    "<img src='images/smiles/grin.gif' smilietext=':gr in:' border='0'
    style='vertical-align:middle' alt=':grin:' title=':grin:' />"
    "<img src='images/smiles/smile.gif' smilietext=': smile:' border='0'
    style='vertical-align:middle' alt=': smile:' title=': smile:' />"
    ¡­..
    from a forum comment.
    >
    I tried this:
    $subject =$row_Recordset 2['pagetext']
    $pattern="/<img src='images\/smiles\/[a-zA-Z]+\.gif' smilietext=':[a-zA-Z]:'
    border='0' style='vertical-align:middle' alt=':[a-zA-Z]:' title=':[a-zA-Z]:'
    \/>/";
    $result = preg_replace($p attern,"",$subj ect);
    But I failed, I am new to PHP, please help. Thanks very much in advance.
    A couple of tips:

    - You can strip HTML tags with strip_tags() or filter_var().
    - You can sanitize HTML output with a third-party library like HTML
    Purifier: http://htmlpurifier.org/

    If you merely want to remove <imgtags then...
    logically, is it a better way to search for all what is inside the <img ...
    /tag (including numbers) and replace them with ""?
    I will write: $pattern="/<img [a-zA-Z][0-9]>\/>/", is it correct? Thank you
    for your help.
    .... try something like:

    $pattern = '@<img\s.*/?>@Uis'; // Not tested

    Just be aware that regexp based HTML parsing tends to fail when faced to
    invalid HTML.



    --
    -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    -- Mi sitio sobre programación web: http://bits.demogracia.com
    -- Mi web de humor al baño María: http://www.demogracia.com
    --

    Comment

    • Paul Jung

      #3
      Re: how to cut a certain group of words in a string?

      WOW!
      thank you so much!
      didn't hear strip HTML tags before, will google it.....
      so far, thank you and have a nice evening!

      Paul


      ""Álvaro G. Vicario"" <alvaroNOSPAMTH ANKS@demogracia .com>
      ??????:gfs87q$c d8$1@huron.algo mas.org...
      Paul Jung escribió:
      >how to cut a certain group of words in a string, for example,
      >"<img src='images/smiles/grin.gif' smilietext=':gr in:' border='0'
      >style='vertica l-align:middle' alt=':grin:' title=':grin:' />"
      >"<img src='images/smiles/smile.gif' smilietext=': smile:' border='0'
      >style='vertica l-align:middle' alt=': smile:' title=': smile:' />"
      >¡­..
      >from a forum comment.
      >>
      >I tried this:
      >$subject =$row_Recordset 2['pagetext']
      >$pattern="/<img src='images\/smiles\/[a-zA-Z]+\.gif'
      >smilietext=' :[a-zA-Z]:' border='0' style='vertical-align:middle'
      >alt=':[a-zA-Z]:' title=':[a-zA-Z]:' \/>/";
      >$result = preg_replace($p attern,"",$subj ect);
      >But I failed, I am new to PHP, please help. Thanks very much in advance.
      >
      A couple of tips:
      >
      - You can strip HTML tags with strip_tags() or filter_var().
      - You can sanitize HTML output with a third-party library like HTML
      Purifier: http://htmlpurifier.org/
      >
      If you merely want to remove <imgtags then...
      >
      >logically, is it a better way to search for all what is inside the <img
      >... /tag (including numbers) and replace them with ""?
      >I will write: $pattern="/<img [a-zA-Z][0-9]>\/>/", is it correct? Thank
      >you for your help.
      >
      ... try something like:
      >
      $pattern = '@<img\s.*/?>@Uis'; // Not tested
      >
      Just be aware that regexp based HTML parsing tends to fail when faced to
      invalid HTML.
      >
      >
      >
      --
      -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
      -- Mi sitio sobre programación web: http://bits.demogracia.com
      -- Mi web de humor al baño María: http://www.demogracia.com
      --

      Comment

      • Paul Jung

        #4
        Re: how to cut a certain group of words in a string?

        >... try something like:
        >>
        >$pattern = '@<img\s.*/?>@Uis'; // Not tested
        IT WORKS GREAT!!!
        WOW!!!
        THANKS!!!


        "Paul Jung" <etjsk@hotmail. comдÈëÏûÏ¢ÐÂÎÅ :b5365$4921a79d $55d8b761$1851@ news.chello.sk. ..
        WOW!
        thank you so much!
        didn't hear strip HTML tags before, will google it.....
        so far, thank you and have a nice evening!
        >
        Paul
        >
        >
        ""Álvaro G. Vicario"" <alvaroNOSPAMTH ANKS@demogracia .com>
        ??????:gfs87q$c d8$1@huron.algo mas.org...
        >Paul Jung escribi?
        >>how to cut a certain group of words in a string, for example,
        >>"<img src='images/smiles/grin.gif' smilietext=':gr in:' border='0'
        >>style='vertic al-align:middle' alt=':grin:' title=':grin:' />"
        >>"<img src='images/smiles/smile.gif' smilietext=': smile:' border='0'
        >>style='vertic al-align:middle' alt=': smile:' title=': smile:' />"
        >>¡­..
        >>from a forum comment.
        >>>
        >>I tried this:
        >>$subject =$row_Recordset 2['pagetext']
        >>$pattern="/<img src='images\/smiles\/[a-zA-Z]+\.gif'
        >>smilietext= ':[a-zA-Z]:' border='0' style='vertical-align:middle'
        >>alt=':[a-zA-Z]:' title=':[a-zA-Z]:' \/>/";
        >>$result = preg_replace($p attern,"",$subj ect);
        >>But I failed, I am new to PHP, please help. Thanks very much in advance.
        >>
        >A couple of tips:
        >>
        >- You can strip HTML tags with strip_tags() or filter_var().
        >- You can sanitize HTML output with a third-party library like HTML
        >Purifier: http://htmlpurifier.org/
        >>
        >If you merely want to remove <imgtags then...
        >>
        >>logically, is it a better way to search for all what is inside the <img
        >>... /tag (including numbers) and replace them with ""?
        >>I will write: $pattern="/<img [a-zA-Z][0-9]>\/>/", is it correct? Thank
        >>you for your help.
        >>
        >... try something like:
        >>
        >$pattern = '@<img\s.*/?>@Uis'; // Not tested
        >>
        >Just be aware that regexp based HTML parsing tends to fail when faced to
        >invalid HTML.
        >>
        >>
        >>
        >--
        >-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        >-- Mi sitio sobre programación web: http://bits.demogracia.com
        >-- Mi web de humor al baño María: http://www.demogracia.com
        >--
        >
        >

        Comment

        Working...