SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: No Bold?

  1. #1
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    No Bold?

    Hi Guys,

    If my text is called out of the DB already with a bold tag. ie:

    <b>This is bold</b><br />

    Is there any way I can simply say ignore the bold tags until it sees nthe <br />?

    Thanks

    Chris

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    dont quite get what you mean chris.
    You can str_replace them on output or striptags. if thats not what you mean you will have to explain more!

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Member Squirrel*Salad's Avatar
    Join Date
    Oct 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can use str_replace() but this will replace all occurances, so try using preg_replace()

    more about it here

    http://uk.php.net/manual/en/function.preg-replace.php
    I am drunk, you are ugly. But in the morning I will be sober.
    Sir Winston Churchill 1963
    ____________________________________________
    www.squirrels-project.co.uk

  4. #4
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Guys. I'll take a look at that!

  5. #5
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    Hmm. Might be being silly here, but I think i'm along the right lines:

    I thought by adding:

    preg_replace("","<b>",$story_text);
    preg_replace("","</b>",$story_text);

    to the below (even tried this in the while loop) when story_text is called out of the DB it would take away the <b></b> tags then using explode I could then get my code to output the first paragraph only?

    However I get the message it's a Empty regular expression?

    Thanks


    PHP Code:

    <? 

    # select all records ordered by date 
    $SQL "Select *, DATE_FORMAT(appeared, '%d %M %Y') as published_date FROM `news_stories` WHERE section='news' AND published <= NOW() ORDER BY id DESC LIMIT 1"

    # Replace the bold tags
    preg_replace("","<b>",$story_text); 
    preg_replace("","</b>",$story_text);

    # make the query (assume connection is there) 
    $result mysql_query($SQL) OR die(mysql_error()); 

    # iterate the result set 
    while ($row mysql_fetch_assoc($result)){ 
    $first_para explode("<br>"$row['story_text']);

        
    $output .= "<div class='story_left'>\n"
        
    $output .= "<div class='date_published'><font color='#CC0000'>Published:</font><font color='#666666'> ".$row['published_date']."</font></div>\n"
        
    $output .= "<div class='time'><br />News</div>\n"
        
    $output .= "<div class='story_headline'><a href='../stories/story.php?id={$row[id]}' class='mouse_headline'>".stripslashes($row[headline])."</a></div>\n";
        
    $output .= "<div class='content_index'>".stripslashes($first_para[0])."</div>\n"
        
    $output .= "<a href='../stories/story.php?id={$row[id]}'><img src='images/more_one.jpg' border='0' width='60' height='15'></a>\n";
        
    $output .= "</div>\n"

    # check if anything is in output 
    if (!$output){ 
       
    $output "No stories found"

    echo 
    "$output"
    ?>

  6. #6
    SitePoint Member Squirrel*Salad's Avatar
    Join Date
    Oct 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    preg_replace("","<b>",$story_text);
    preg_replace("","</b>",$story_text);
    PHP Code:
     
    $story_text 
    str_replace("<b>","",$story_text); 
    $story_text str_replace("</b>","",$story_text); 
    But this will replace all occurances of the <b> and </b> tags.

    In your origonal post you said upto the first <br /> tag so do you want to replace all instances or just the first?

    or i have just thought of another method strip_tags() but again it will remove all instances and only leave behind the tags you tell it to. In the example below I have told it to leave the <br /> tag alone, everything else will be removed so if your text also has <p> <pre> etc etc they will also be removed.

    PHP Code:
     
    $story_text 
    strip_tags$story_text"<br />"); 
    I am drunk, you are ugly. But in the morning I will be sober.
    Sir Winston Churchill 1963
    ____________________________________________
    www.squirrels-project.co.uk

  7. #7
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep,

    sorry did mean preg_replace & not str_replace.

    Have kind of worked it out for myself now, although:

    PHP Code:
    $first_para explode("<br>"$row['story_text']);

    $first_para preg_replace("<b>","",$first_para);
    $first_para preg_replace("</b>","",$first_para); 
    It for some reason replaces all the letter 'b' and not my <b></b> tags?

    Thanks

  8. #8
    SitePoint Member Squirrel*Salad's Avatar
    Join Date
    Oct 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to change < to either &#60 or &lt; and > to &#62 or &gt;
    I am drunk, you are ugly. But in the morning I will be sober.
    Sir Winston Churchill 1963
    ____________________________________________
    www.squirrels-project.co.uk

  9. #9
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you!

  10. #10
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, but last one:

    Tried:

    $first_para = preg_replace("&#60b&#62","",$first_para);

    But Unknown modifier '#' ?

    Thanks

    Chris

  11. #11
    SitePoint Member Squirrel*Salad's Avatar
    Join Date
    Oct 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7724
    Sorry, but last one:

    Tried:

    $first_para = preg_replace("&#60b&#62","",$first_para);

    But Unknown modifier '#' ?

    Thanks

    Chris
    sorry my fault this will work,

    PHP Code:
     
    $first_para 
    preg_replace("(<b>)"""$first_para );

    $first_para preg_replace("(</b>)"""$first_para ); 
    I am drunk, you are ugly. But in the morning I will be sober.
    Sir Winston Churchill 1963
    ____________________________________________
    www.squirrels-project.co.uk

  12. #12
    SitePoint Addict ruba's Avatar
    Join Date
    Apr 2005
    Location
    Amman -Jordan
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if you can use

    strip-tags

    http://www.php.net/manual/en/function.strip-tags.php

  13. #13
    SitePoint Member Squirrel*Salad's Avatar
    Join Date
    Oct 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there are may ways to remove tags, but it all depends on what your doing. This is why i suggested either str_replace or preg_replace. Personally i use preg_replace as you get better control on instancies.
    I am drunk, you are ugly. But in the morning I will be sober.
    Sir Winston Churchill 1963
    ____________________________________________
    www.squirrels-project.co.uk

  14. #14
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    If you dont want ANY html code in it use strip_tags, if you might need some use preg_replace.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


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
  •