SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    Bucharest
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy A REGEXP master is wanted

    So, mysql 4.0.22 on the server.
    For a newsletter system (written in php), the customer want to recieve the e-mail message not as HTML, just plain text.
    As you my guested allready, the field is of type TEXT (let`s name it news_body) and I`m keeping there some HTML code that is sended to the subscriber.
    The problem is that i don`t want to select html tags from there if the customer wants to recieve the mail as plain text.
    Assuming that I have something like this on the db field:

    How it works?<br />Try the <a href="http://www.php.net/tut.php">introductory tutorial</a>.<br />
    After that, <i>check out <span class="regular">this <a href="www.ex.com">topic</a></span></i><br />

    I just want to get:

    How it works?Try the introductory tutorial.After that, check out this topic.

    for the guy that don`t wana html e-mail.

    Any hints?

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is what you want

    PHP Code:
      
     $html_text 
    'How it works?<br />Try the <a href="http://www.php.net/tut.php">introductory tutorial</a>.<br /> After that, <i>check out <span class="regular">this <a href="www.ex.com">topic</a></span></i><br />';
      
      
    $txt preg_replace('|<(.*)>|'''$html_text);
      
      echo 
    'Here\'s the plain text ~' $txt '~<br />'
    However, this means that the person receivig this plain text email will have no idea where the links point to.
    Better would be to place the links as plain text, but that involves much more work.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    Bucharest
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tanks for your quick reply.
    The problem is a more complex since I want to use mysql SELECT REGEXP to get my field content.
    At this poit, the query looks like this:
    PHP Code:
    SELECT
    `n_news_title`, REPLACE(`n_news_title`, ' ','%20') AS `subject`, 
    DATE_FORMAT(`n_news_added`,'%a, %d %b %Y %H:%i:%s') as `n_news_added`,
    SUBSTRING(`n_news_body`,1,101) AS `n_news_body
    FROM news ORDER BY `n_news_addedDESC LIMIT 5
    As you can see, I`m selecting the _news_title_ (witch will be the email subject), I also need a proper date format field, and the most important one, I just want the first 100 characters from the news body and here i must remove the html tags.

    The same query is used to build a rss feed (you can see it here: http://fastwork.locknet.ro/feeds/news.xml and you will notice that I have html tags there).

    In the end, if I will not find a solution, I will use your php code, so tanx.

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    Bucharest
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, I guess is no possibile to make only one select here and to get all the infos I needed.

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    Bucharest
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    This is not posible

    For other people that are looking for something similar:
    Is not posible to select the first n characters (let`s say 100) from a TEXT field without counting (and selecting) everything that is inside HTML tags.

    So all you need to do:

    1. select 150 characters
    2. using swdev code remove all the html code
    3. count the characters again (in your script). If you were lucky you will get 100 chars, if not go to step 1 again.

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    Bucharest
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    A work-around might be:

    1. Select your field (it dosnt meater if is the Romanian Constitution Translated in French).
    2. Use swdev code on the result to remove all the HTML format.
    3. Count the first 100 char.
    4. Send the mail


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •