Re: [PHP] RegEx (back referencing)

2002-08-03 Thread Danny Shepherd

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  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




Re: [PHP] RegEx (back referencing)

2002-08-03 Thread Danny Shepherd

If you're trying to get Lots of javascript to look like
Lots of javascript then this will be a start

$string = eregi_replace('<(/?)(scr[^>]*)>', '<\\1font
color="maroon">',$string);

This will produce -  Lots of javascript - 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  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




RE: [PHP] RegEx (back referencing)

2002-08-03 Thread Phil Ewington

What's strange is that doing an ord($string) returns 171, which is a '1/2'
char. So why does PHP convert the pattern match??


> -Original Message-
> From: Phil Ewington [mailto:[EMAIL PROTECTED]]
> Sent: 03 August 2002 17:04
> To: PHP General
> 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  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




RE: [PHP] RegEx (back referencing)

2002-08-03 Thread Phil Ewington

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 Lots of javascript to look like
> Lots of javascript then this will be a start
>
> $string = eregi_replace('<(/?)(scr[^>]*)>', '<\\1font
> color="maroon">',$string);
>
> This will produce -  Lots of javascript 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  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




Re: [PHP] RegEx (back referencing)

2002-08-03 Thread Danny Shepherd

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 Lots of javascript to look like
> > Lots of javascript then this will be a start
> >
> > $string = eregi_replace('<(/?)(scr[^>]*)>', '<\\1font
> > color="maroon">',$string);
> >
> > This will produce -  Lots of javascript > 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  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




Re: [PHP] RegEx (back referencing)

2002-08-03 Thread Danny Shepherd

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  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:#FF;
> background-color:#00; padding:5px;\">$filename</div>
> <div style=\"font-family:courier new, mono; font-size:x-small;
> background-color:#EE; padding:10px; border:1px #00
> solid;\">$fcontent</div>
> </div>";
>
> ?>
>
> The output looks as follows (so far)...
> <A  HREF="http://www.n-igma.net/regex.php">http://www.n-igma.net/regex.php</A>
>
> 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 [<A  HREF="mailto:[EMAIL PROTECTED]">mailto:[EMAIL PROTECTED]</A>]
> > 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 [<A  HREF="mailto:[EMAIL PROTECTED]">mailto:[EMAIL PROTECTED]</A>]
> > > > 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
> > to look like
> > > > Lots of javascript then this will
> > be a start
> > > >
> > > > $string = eregi_replace('<(/?)(scr[^>]*)>', '<\\1font
> > > > color="maroon">&#x

Re: [PHP] RegEx (back referencing)

2002-08-04 Thread Analysis & Solutions

On Sat, Aug 03, 2002 at 05:03:36PM +0100, Phil Ewington wrote:
> 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.

What you're using isn't "back referencing," it's utilizing "substrings."  
Back referencing is when you bring the substrings back into the regular 
expression definition.
 

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

Here's what your command asks PHP to do:  Find any opening or 
closing script tag and replace it with "«font color=maroon»\1«/font»."
That's not what you intend.  Let's make a test script:

   java is dumb end';

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

   echo "$string\n";

   ?>


This is what comes out:

   begin «font color=maroon»«/font»java is dumb«font color=maroon»«/font»
   end


First off, if you want to utilize substrings, you need to use two
backslashes. "\\1" instead of "\1".  Second, \\1 refers to the first
parenthesized part of the pattern, which in the pattern you set up is the
forward slash at the beginning of the script tag.  So, let's modify the 
pattern accordingly and see what happens:

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

Creates:

begin «font color=maroon»«/font»java is dumb«font color=maroon»/«/font»
end


But, that's still not what you intend.  I think you're really looking to
surround the scripts with maroon font tags.  To do that, you need to tweak
the expression to grab the script tags, the script itself and the closing
script tag.

   $string = eregi_replace('(]*>[^<]*)',
'\\1', $string);

Outputs:

   begin java is dumb end


Notice the use of ' rather than ", which saves a little processor time by 
not evaluaing the strings for variables.

One final improvement.  Font tags are obnoxious.  They cause problems for
people that choose their own background colors in their browsers.  Read
http://www.analysisandsolutions.com/code/weberror.htm?ft=y for more info
on that.  Anyway, I suggest using Cascading Style Sheets,
http://www.w3.org/TR/REC-CSS1, for the colroing instead:

   $string = eregi_replace('(]*>[^<]*)',
'\\1', $string);

   echo "code.js {color: maroon;}\n";
   echo "$string\n";

Yields:

   code.js {color: maroon;}
   begin java is dumb end

Voila!

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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