How do i find the fontsize pattern?

Discussion in 'PHP' started by 123GoToAndPlay, Oct 17, 2008.

  1. #1
    Hi,

    I like to replace the font-size tag with nothing, so
    
    style="font-size: 10pt; color: black; font-family: Verdana"
    
    style="font-size: 14pt; color: blue; font-family: Verdana"
    
    Code (markup):
    reads

    
    style=" color: black; font-family: Verdana"
    
    style=" color: blue; font-family: Verdana"
    
    Code (markup):
    
    
    $newContent = preg_replace("/font-size=/","", $content);
    
    [code]
    
    but this doesn't work
    Code (markup):
     
    123GoToAndPlay, Oct 17, 2008 IP
  2. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use this, its working:
    
    <?php
    $newContent = explode("font-size:",$content);
    $newContent = explode(";",$newContent[1]);
    $array = array("font-size:",$newContent[0]);
    $newContent = str_ireplace($array,"",$content);
    $newContent = str_ireplace("; color","color",$newContent);
    echo $newContent;
    ?>
    PHP:
    Thanks!
     
    mehdi, Oct 17, 2008 IP
  3. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I don't get what's your problem.
    I'm just trying:

    $newContent = str_replace('style="', 'style="font-size: 10px; ', $content);
    PHP:
     
    djzmo, Oct 17, 2008 IP
  4. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hmm,

    @mehdi, i stil get the ..pt, oh and some <style tags have a color property and some don't so i don't want to use the color propertu

    @djzmo, i want to get rid of the font-size property and it has different ...pt. So not only 10px
     
    123GoToAndPlay, Oct 17, 2008 IP
  5. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry dude, i dn't understand wht u are talking about?
     
    mehdi, Oct 17, 2008 IP
  6. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #6
    
    $content = 'style="font-size: 10pt; color: black; font-family: Verdana"
    style="font-size: 14pt; color: blue; font-family: Verdana"';
    $newContent = preg_replace("/font\-size\:\s([0-9]*)pt;/","", $content);
    print $newContent;
    
    PHP:
    Tested this using my Regex Tester.
    At the regex tester, paste your string and use this pattern : /font\-size\:\s([0-9]*)pt;/
    Try it yourself.

    Good luck.
     
    ads2help, Oct 17, 2008 IP