Bluehost.com Web Hosting $6.95

Can't seem to create a simple pattern matching function due to character than won't allow me to escape it.

This is a discussion on Can't seem to create a simple pattern matching function due to character than won't allow me to escape it. within the PHP Language forums, part of the PHP Programming Forums category; Hi everyone. I am looking to create a simple function that will spot a hexcolor in a font tag, that ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-14-2006
Daz
 
Posts: n/a
Default Can't seem to create a simple pattern matching function due to character than won't allow me to escape it.

Hi everyone. I am looking to create a simple function that will spot a
hexcolor in a font tag, that has quotes, and remove the quotes. i.e
<font color="ffffff"> should become <font color=ffffff>.

Perhaps I am making it more complex than it needs to be, but I have
broken down the input string into an array of single characters using
preg_split(), and I am iterating through the chars, looking for a quote
followed by a hash. The problem appear to be with the hash. Although it
prints out fine, not amount of escaping the hash seems to allow me to
match it. Instead preg_match() match spaces (obviously because the
veriable I am using to store the '#', is not storing it properly.

Please could someone put me out of my misery by either hinting towards
a simpler way to do it, or just shooting me?

I am sure there are at least 100 different ways of using regex to
achieve what I want, but I can't think how. Perhaps I am just looking
at the wrong functions?

Many thanks.

Daz.

Reply With Quote
  #2 (permalink)  
Old 10-15-2006
Chung Leong
 
Posts: n/a
Default Re: Can't seem to create a simple pattern matching function due to character than won't allow me to escape it.

Daz wrote:
> Hi everyone. I am looking to create a simple function that will spot a
> hexcolor in a font tag, that has quotes, and remove the quotes. i.e
> <font color="ffffff"> should become <font color=ffffff>.
>
> Perhaps I am making it more complex than it needs to be, but I have
> broken down the input string into an array of single characters using
> preg_split(), and I am iterating through the chars, looking for a quote
> followed by a hash. The problem appear to be with the hash. Although it
> prints out fine, not amount of escaping the hash seems to allow me to
> match it. Instead preg_match() match spaces (obviously because the
> veriable I am using to store the '#', is not storing it properly.
>
> Please could someone put me out of my misery by either hinting towards
> a simpler way to do it, or just shooting me?
>
> I am sure there are at least 100 different ways of using regex to
> achieve what I want, but I can't think how. Perhaps I am just looking
> at the wrong functions?
>
> Many thanks.
>
> Daz.


Why not just preg_replace('/(<font\s+color\s*=\s*)"(#[0-9a-f]+)"/si',
'\1\2', $html)?

Reply With Quote
  #3 (permalink)  
Old 10-16-2006
Daz
 
Posts: n/a
Default Re: Can't seem to create a simple pattern matching function due to character than won't allow me to escape it.


Chung Leong wrote:
> Daz wrote:
> > Hi everyone. I am looking to create a simple function that will spot a
> > hexcolor in a font tag, that has quotes, and remove the quotes. i.e
> > <font color="ffffff"> should become <font color=ffffff>.
> >
> > Perhaps I am making it more complex than it needs to be, but I have
> > broken down the input string into an array of single characters using
> > preg_split(), and I am iterating through the chars, looking for a quote
> > followed by a hash. The problem appear to be with the hash. Although it
> > prints out fine, not amount of escaping the hash seems to allow me to
> > match it. Instead preg_match() match spaces (obviously because the
> > veriable I am using to store the '#', is not storing it properly.
> >
> > Please could someone put me out of my misery by either hinting towards
> > a simpler way to do it, or just shooting me?
> >
> > I am sure there are at least 100 different ways of using regex to
> > achieve what I want, but I can't think how. Perhaps I am just looking
> > at the wrong functions?
> >
> > Many thanks.
> >
> > Daz.

>
> Why not just preg_replace('/(<font\s+color\s*=\s*)"(#[0-9a-f]+)"/si',
> '\1\2', $html)?


Because I forgot how to get the matched text from the regex pattern
match. Hehe.

Many thanks for that. :)

Daz

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:26 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0