Ok, a very slightly modified version of your first attempt should work then

$fcontent = eregi_replace("<(/?)(scr[^>]*)>", "«font
color=maroon»\\0«/font»", $fcontent);

Note the \\0 instead of \\1

HTH

Danny.

----- Original Message -----
From: "Phil Ewington" <[EMAIL PROTECTED]>
To: "Danny Shepherd" <[EMAIL PROTECTED]>
Sent: Saturday, August 03, 2002 8:54 PM
Subject: RE: [PHP] RegEx (back referencing)


> Danny,
>
> OK, the input string is the contents of a file, the idea is to output
color
> coded and indented code in HTML. So searching for <script> and replace
with
> <font color=maroon><script></font>, so the <script> tag shows on a page. I
> am slowly converting a ColdFusion script which currently color codes CFML,
> HTML, JS & PHP code.
>
> // get file and pass into string
> $filename = "/path_to_file/newsfeed.js";
> $fcontent = implode("", file($filename));
>
> // convert new lines, tabs and multiple spaces
> $fcontent = eregi_replace(chr(10), "«br»", $fcontent);
> $fcontent = eregi_replace(chr(9), "&nbsp;&nbsp;&nbsp;&nbsp;", $fcontent);
> $fcontent = eregi_replace(" {2,2}", "&nbsp;&nbsp;", $fcontent);
>
> // color code script
> $fcontent = eregi_replace("<(/?)(scr[^>]*)>", "«font
> color=maroon»\\1«/font»", $fcontent);
>
> // allow html tags in strings to print
> $fcontent = eregi_replace("[^('|\")]<br>[^('|\")]", "«br»", $fcontent);
>
> // allow script tags to display
> $fcontent = eregi_replace("<", "&lt;", $fcontent);
> $fcontent = eregi_replace(">", "&gt;", $fcontent);
> $fcontent = eregi_replace("«", "<", $fcontent);
> $fcontent = eregi_replace("»", ">", $fcontent);
>
>
> // get filename from path
> $filename = explode("/", $filename);
> $filename = $filename[count($filename) - 1];
>
> // print formatted content
> print "\n
> <div>
> <div style=\"font-family:verdana; font-size:x-small; color:#FFFFFF;
> background-color:#000000; padding:5px;\">$filename</div>
> <div style=\"font-family:courier new, mono; font-size:x-small;
> background-color:#EEEEEE; padding:10px; border:1px #000000
> solid;\">$fcontent</div>
> </div>";
>
> ?>
>
> The output looks as follows (so far)...
> http://www.n-igma.net/regex.php
>
> Got the indenting sorted, now needs to be color coded.
>
> I am using an old version as I know very little about *nix and compiling
the
> binaries for PHP on a RAQ3 was a headache, well for a Windows user any way
> ;o) I have not wanted to upgrade yet as I have a number of sites running
on
> the box and haven't had the balls to in case I screw it up again!
>
>
> Phil.
> > -----Original Message-----
> > From: Danny Shepherd [mailto:[EMAIL PROTECTED]]
> > Sent: 03 August 2002 18:26
> > To: [EMAIL PROTECTED]; PHP General
> > Subject: Re: [PHP] RegEx (back referencing)
> >
> >
> > What does the input string contain?
> >
> > What does the output look like?
> >
> > It might be a problem with php4.0.4 (I'm using 4.2.2) - why such an old
> > version?
> >
> > Danny.
> >
> > ----- Original Message -----
> > From: "Phil Ewington" <[EMAIL PROTECTED]>
> > To: "PHP General" <[EMAIL PROTECTED]>
> > Sent: Saturday, August 03, 2002 6:23 PM
> > Subject: RE: [PHP] RegEx (back referencing)
> >
> >
> > > Danny,
> > >
> > > It still doesn't work, could this be a problem in 4.0.4pl1 ??
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: Danny Shepherd [mailto:[EMAIL PROTECTED]]
> > > > Sent: 03 August 2002 18:11
> > > > To: [EMAIL PROTECTED]; PHP-General
> > > > Subject: Re: [PHP] RegEx (back referencing)
> > > >
> > > >
> > > > If you're trying to get <script>Lots of javascript</script>
> > to look like
> > > > <font color="maroon">Lots of javascript</font> then this will
> > be a start
> > > >
> > > > $string = eregi_replace('<(/?)(scr[^>]*)>', '<\\1font
> > > > color="maroon">',$string);
> > > >
> > > > This will produce -  <font color="maroon">Lots of javascript</font
> > > > color="maroon"> - not perfect, but a start.
> > > >
> > > > Danny.
> > > >
> > > > ----- Original Message -----
> > > > From: "Phil Ewington" <[EMAIL PROTECTED]>
> > > > To: "Danny Shepherd" <[EMAIL PROTECTED]>
> > > > Sent: Saturday, August 03, 2002 5:52 PM
> > > > Subject: RE: [PHP] RegEx (back referencing)
> > > >
> > > >
> > > > > \\1 outputs nothing at all wrapped in font tags and closing
> > > > tags \ wrapped
> > > > > in font tags :o(
> > > > >
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Danny Shepherd [mailto:[EMAIL PROTECTED]]
> > > > > > Sent: 03 August 2002 17:47
> > > > > > To: [EMAIL PROTECTED]; PHP General
> > > > > > Subject: Re: [PHP] RegEx (back referencing)
> > > > > >
> > > > > >
> > > > > > try
> > > > > >
> > > > > > \\1
> > > > > >
> > > > > > ----- Original Message -----
> > > > > > From: "Phil Ewington" <[EMAIL PROTECTED]>
> > > > > > To: "PHP General" <[EMAIL PROTECTED]>
> > > > > > Sent: Saturday, August 03, 2002 5:03 PM
> > > > > > Subject: [PHP] RegEx (back referencing)
> > > > > >
> > > > > >
> > > > > > > Hi,
> > > > > > >
> > > > > > > I am am writing a function to color code and indent
> > > > JavaScript source
> > > > > > using
> > > > > > > regular expressions and cannot seem to get back referencing
> > working.
> > > > The
> > > > > > > pattern match is successful but the output is a single
> > unrecognised
> > > > > > > character (a square).
> > > > > > >
> > > > > > > $string = eregi_replace("<(/?)(scr[^>]*)>", "«font
> > > > > > color=maroon»\1«/font»",
> > > > > > > $string);
> > > > > > >
> > > > > > > This results in opening and closing <script></script> tags
> > > > > > being replaced
> > > > > > > with a square being wrapped in font tags. I have this
> > > > working in Cold
> > > > > > Fusion
> > > > > > > but cannot seem to convert my scripts to PHP. Can anyone help?
> > > > > > >
> > > > > > > TIA
> > > > > > >
> > > > > > > Phil Ewington.
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > PHP General Mailing List (http://www.php.net/)
> > > > > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > PHP General Mailing List (http://www.php.net/)
> > > > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > > > >
> > > > >
> > > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to