Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Good regex?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
I'm in the process of writing a Mailing list. It supports both plain and HTML emails. The problem I am having is replacing all the \n's ONLY on lines that do not have HTML on! This is getting to be a real pain :( Anyone know of any good regex to do this?

Thanks...and any help is much appreciated :)

Andy
 
code would be useful ***************************************
Party on, dudes!
[cannon]
 
I've got something similar to this at the moment;

$message = ereg_replace(&quot;\n&quot;, &quot;<BR>&quot;, $message);

I was thinking of something more along the line of;

if (eregi(&quot;/^someregex/i&quot;, $message)) {

$message = ereg_replace(&quot;\n&quot;, &quot;<BR>&quot;, $message);

} else {

// don't do anything here...cos $message didnt look like it had HTML in it...

}
 
nah just use

nl2br($message) ***************************************
Party on, dudes!
[cannon]
 
But will this verify if the line has HTML? Thats the main problem I've got. It keeps replacing all newline breaks with <BR>'s, whereas I only need new lines without HTML code on to have the <BR>s inserted.

Thanks for the extremly fast replies :)

Andy
 
OK post a sample message and I'll ponder while I play connect 4 with my daughter :) ***************************************
Party on, dudes!
[cannon]
 
Something like

Code:
<HTML>
<BODY>
<HEAD>

<font color=red>some word test</font>

</HEAD>
</BODY>
</HTML>

and it ends up something like;

Code:
<HTML><BR>
<BODY><BR>
<HEAD><BR>
<BR>
<font color=red>some word test</font><BR>
<BR>
</HEAD><BR>
</BODY><BR>
</HTML><BR>

Thanks :)
 
OK this will add <br> to lines not conatining html and to blank lines.(incidentally you can call this test.php ad then point it at a html file to get an idea of output like message html file>
if (isset($message)){
<?php
$fcontents = file($message);

while (list ($line_num, $line) = each ($fcontents)) {

if (isset($line) && ereg(&quot;^<.+>.+&quot;,$line)) {

echo &quot;$line&quot;;

} else{

echo nl2br($line);

}
}

}else{

echo &quot;no message specified&quot;;

}
?> ***************************************
Party on, dudes!
[cannon]
 
why do these things post extra stuff.
move the first <?php to above the isset($message) line and ignore (dont put in) the ; in the url code. ***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top