Jump to content

Simple Regex problem


techcone

Recommended Posts

I have a text file containing this :

 

<font face="Book Antiqua"><font size="5"><font color="Orange">asdasdasdasd</font></font></font>

 

I want to replace second font tag with this

 

[size=5]

 

so code appears

 

<font face="Book Antiqua">[size=5]<font color="Orange">asdasdasdasd</font>[/size]</font>

 

But I am getting :

 

<font face="Book Antiqua">[size=5]<font color="Orange">asdasdasdasd</font></font>[/size]

 

or this

 

<font face="Book Antiqua">[size=5]<font color="Orange">asdasdasdasd[/size]</font></font>

 

depending on whether i use ? or not. How can i select middle tag ?

 

Regex used :

 

<font size=\"(.*?)\">(.*?)<\/font>

Link to comment
https://forums.phpfreaks.com/topic/136707-simple-regex-problem/
Share on other sites

what are you trying to do?  what is ""  That's not HTML, CSS or anything i've seen, so maybe that is why I'm confused?

 

Are you trying to make the font size dynamic, so it can be adjusted by the user?  If so, just use a variable.


<?PHP
$fontSIZE = $_GET['size'];

?>

<font face="Book Antiqua" size="<?PHP echo $fontSIZE; ?>" color="Orange">asdasdasdasd</font>

 

Again - if you could explain a little more, maybe there is a better solution?

 

j

Link to comment
https://forums.phpfreaks.com/topic/136707-simple-regex-problem/#findComment-713948
Share on other sites

Even a better idea...CSS:

 

#techcone
{
    font-size: 11px;
    color: #FF9900;
    font-family: book antiqua;
}

 

<html>
<head>
  	
    <title>More Cowbell</title>
  
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="robot" content="index, follow" />
    
    <link rel="stylesheet" type="text/css" href="style.css" /> 
    
</head>

<body>

  <div id="techcone">
    The font size, color and font family have been defined in your CSS!!
  </div>

</body>
</html>

 

Now....if you are trying to make it dymaic (Your example code isn't clear, as you're using a non HTML tag), you'd use a different method. But you can even use a dynamic style sheet for that as well.

Link to comment
https://forums.phpfreaks.com/topic/136707-simple-regex-problem/#findComment-714013
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.