f



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.

0
cutenfuzzy (260)
10/14/2006 7:33:46 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

2 Replies
634 Views

Similar Articles

[PageSpeed] 57

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

0
chernyshevsky (2297)
10/15/2006 4:49:56 AM
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

0
cutenfuzzy (260)
10/16/2006 5:52:12 PM
Reply:

Similar Artilces:

Willie won't, Willie won't, won't go!
Ah yes, some 70s nostalgia tunes. ...

Files won't display, directory won't delete, drive won't format
After having a few slow-access problems, I ran a virus scan (McAfee) on my D: drive (second HDD, 15Gb). To my surprise, the scan listed a directory and files which I didn't recognise: I didn't note any full pathnames, but a typical one was something like D:\RECYCLER\S-1-5-21... Dd159.zip . I wondered if this was anything to do with the Recycle bin, despite the fact that I'd emptied it immediately before the scan. No viruses were detected, but when I ran an error check I got the message "the scan could not be completed". As a precaution I decided to ba...

Can't understand why this won't compile
The problem code: // line 0 template <class T, T* (T::*C)(void) const> class cc { }; // line 6 class e { public: virtual e *clone(void) const; cc<e,&clone> ee(void) const; }; This code causes problems with both Visual C++ 7 (2003) and g++ 2.96. With VC, I get the following error message: c:\Documents and Settings\CJ\My Documents\Projects\Project Grapher\Source Code\Expression.cpp(22): fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 2701) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information In g++, I get two different results. Whith the code above, I get the following: test.cpp:12: invalid use of undefined type `class e' test.cpp:8: forward declaration of `class e' test.cpp:12: template argument 2 is invalid test.cpp:12: ISO C++ forbids declaration of `ee' with no type When using &e::clone instead of &clone, g++ reports: test.cpp:12: Internal error: Segmentation fault. (with the same change, VC still has an internal compiler error) Unless, for some reason, I really can't use e from within e (which I know can't be right), I can't see the reason for these error messages. Anyone know what's going on? Should this code not compile anyway? Thanks for you time -CJ contact: http://stude...

Can't shutdown. Won't shutdown.
My Mac Mini, version OSX 10.4.9, refuses to shut down correctly. The monitor displays a grey screen telling me I must switch off the Mini using the power button. I humbly obey but, when I switch on again, an annoying message tells me that the damned thing shut down unexpectedly. A minor and trivial niggle, I'm sure, but is there anything I can do to sort it? "Davo" <u33430@uwe> writes: >My Mac Mini, version OSX 10.4.9, refuses to shut down correctly. The monitor >displays a grey screen telling me I must switch off the Mini using the power >button. This sounds ...

I don't work for IBM and I don't make promises I can't deliver on
I wish I could afford an advertising campaign to compete with what they have on the Internet now. I promise to go totally ballistic at the next LLLNL contract. Robert. On 8/12/2011 11:24 PM, Robert Myers wrote: > I wish I could afford an advertising campaign to compete with what they > have on the Internet now. > > I promise to go totally ballistic at the next LLLNL contract. > > Robert. I don't work for IBM (anymore) either. If you are talking about the death of Blue Waters, I don't believe they said they couldn't deliver. They said they chose not to because they would lose a bunch of money on the project since it turned out to cost a lot more than the initial guess. And I guess Ben chose not to print some more to pay for it. On Aug 24, 11:17=A0pm, Del Cecchi <delcec...@gmail.com> wrote: > On 8/12/2011 11:24 PM, Robert Myers wrote: > > > I wish I could afford an advertising campaign to compete with what they > > have on the Internet now. > > > I promise to go totally ballistic at the next LLLNL contract. > > > Robert. > > I don't work for IBM (anymore) either. =A0If you are talking about the > death of Blue Waters, I don't believe they said they couldn't deliver. > They said they chose not to because they would lose a bunch of money on > the project since it turned out to cost a lot more than the initial guess= .. > > And I guess Ben chose not to print some mor...

why can't I create 'timer'
when I create a timer object as follows t = timer and I get a error message. Undefined function or variable 'timer' why can't I create 'timer'? I use matlab version 6.1 "likeforever" <likeforever@126.com> wrote in message news:13419325.1115980328942.JavaMail.jakarta@nitrogen.mathforum.org... > when I create a timer object as follows > t = timer > and I get a error message. > Undefined function or variable 'timer' > why can't I create 'timer'? > I use matlab version 6.1 Because timer objects had not yet been introduc...

Help: I can't figure out why this won't work
I have a hyperlink on an ASP page that calls another ASP page with the code shown below. This page allows (forces) a user to select a file to be uploaded, then should call a third ASP page that will do the actual upload. What happens is I can enter a file name but the third page doesn't get loaded. I see the upload page being called in the browser when the alert message displays, but then it appears to reload this page. What am I missing??? I should also note that the upload page opens fine if I move the location.href command outside of the function (for testing purposes). <FORM N...

third program can't find why it won't work.
I am learning javascript from a book. I admit it is not the easiest or best way, but I wanted to learn and I had the books purchased from awhile back. I have some familiarity with C and HTML and wanted to expand my programming base. I have tried two of the programs in this book and they worked fine. Now on the third one I can't seem to get it to work. I know it is probably something simple but could you give it a look and steer me in the right direction? Here is the code the Script and HTML commands are commented out. I thought is was suppose to return a total value. <!--ml> <he...

Forms/Tables that can't/won't hold scroll
Hi all, I've tried finding an answer in the history, but only find a lot of historical posts where people didn't get answers to the same problem up to 5 or 6 years ago! I'm having a problem with Access2003 on Windows XP Pro where I often can't scroll. On some tables, I scroll vertically using the scroll bars, but when I let off the mouse button, it jumps back to whereever my cursor is. On some forms, if I don't have data to display, my users with smaller screens can't scroll to the right to see hidden buttons/drop downs. Does anyone know what's going on? Are these related problems? They don't happen in any other applications, and only in certain circumstances within Access. TIA, Jon On Mar 21, 12:48 pm, "jonceramic" <joncera...@gmail.com> wrote: > Hi all, > > I've tried finding an answer in the history, but only find a lot of > historical posts where people didn't get answers to the same problem > up to 5 or 6 years ago! > > I'm having a problem with Access2003 on Windows XP Pro where I often > can't scroll. > > On some tables, I scroll vertically using the scroll bars, but when I > let off the mouse button, it jumps back to whereever my cursor is. > > On some forms, if I don't have data to display, my users with smaller > screens can't scroll to the right to see hidden buttons/drop downs. > > Does anyone know what's going on? Are these relat...

Why won't this work? (can't find prior posting of this problem)
I have a control on a form whose data source is: =IIf([txtPercentTotal]=1,"Total is 100%",IIf([txtPercentTotal]>1,"Total is Over 100%; Please Adjust",IIf([txtPercentTotal]<1,"Total is UNDER 100%; Please Adjust"))) I have tried =IIf([txtPercentTotal]>1,"Total is Over 100%; Please Adjust",IIf([txtPercentTotal]<1,"Total is UNDER 100%; Please Adjust","Total is 100%")) and =IIf([txtPercentTotal]>1,"Total is Over 100%; Please Adjust",IIf([txtPercentTotal]<1,"Total is UNDER 100%; Please Adjust",IIf([txtPercentTotal]=1,"Total is 100%")) The problem is that I never get the "Total is 100%" message, even when it's 1. I have tried adding the 14 values in Excel and they come to 1.00. I have put the decimal places to 4 and 5 and it's all zeroes. I typed the values into the table and want (ultimately) to enter them via a form. Thanks Sara =IIf([txtPercentTotal]=1;"Total is 100%"; IIf([txtPercentTotal]>1;"Total is Over 100% Please Adjust"; IIf([txtPercentTotal]<1;"Total is UNDER 100%";"Please Adjust"))) ...

SGI Fuel won't boot, can't access PROM
I'm having a serious problem booting an SGI Fuel. I believe it is running IRIX 6.5 and the PROM is version 6.144. The system was working but no one knew the root password. Of course I tried getting into single user mode by typing 'single' at the PROM console which started a boot then the screen went blank and the system became nonresponsive. I tried using 2 different overlay installation CD's (can't find original OS) to boot but both appear to lock up the graphics after copying files to the harddrive (before any menus even come up). I've tried connecting a null-modem cable to COM1 from an XP PC running hyperterminal (9600 8-N-1) but have never been able to get any output to the terminal. I've tried with and without the keyboard and mouse plugged into the Fuel. In an attempt to get this working I was playing with environment variable in the PROM and may have changed something that's caused my current situation. I set the following: console=d AutoBoot=No When the Fuel is turned on, the 3 lights on the keyboard flash as normal; the LED on the case flashed white for a bit then goes solid white (normal I think); but the monitor never turns on! Usually the monitor would come on maybe 10 seconds after the flashing keyboard lights, just in time to see the graphical display prompting to enter Maintenance Mode. If I press the power button on the Fuel at this point it shuts down immediately. The last thing I did in the PROM console was run ...

can't get the $_GET['id'] after the header is sent but page doesn't redirect
In the first if, the page is displayed without any company cars selected. If there is a company selected, then the id value is posted and captured by the redirect (1st elseif). Then one of two things can happen. The final else the selected company/id cars get displayed in the browser, or in the case of a post to a form for excel, the a header gets sent to the to the current_sightingsXL.php page. The current_sightingsXL.php and current_sightings.php pages test out. The second elseif works with one minor problem. I have to type in the url with the id to get it to download to excel. if{XXXX }elseif($_POST['redirect']&&$_POST['redirect']!=$_SERVER['PHP_SELF']){ Header("Location: ".$_POST['redirect'].".php?id=".$_POST['id']); exit; }elseif($_POST['assign']=='Open in Excel'){ Header("Location: current_sightingsXL.php?id=".$_GET:['id']); exit; }else{ xxxxx}; When the first elseif gets hit then this happens in the url: http://www.allcapitalrail.com/current_sightings.php?id=117 Then if I post the button to excel, this should happen but it doesn't: www.allcapitalrailXL.com?id=117 However, if I type the above line in the url then the excel download works. What happens is when I click the excel post button the get id doens't get into the url. I get www.allcapitalrail.com which starts over. But at this point if I type in the www.allcapitalrail.com/...

'ascii' codec can't encode character u'\xe4' in position 4: ordinal not in range(128)
Hello friends, I am using pyWPS + GRASS to generate the maps for the given request XML. As my requestxml contains scandinavian letters , i got the following error, " 'ascii' codec can't encode character u'\xe4' in position 4: ordinal not in range(128) " The Request xml also contains encoding specification like <?xml version="1.0" encoding="UTF-8" standalone="yes"?> Then i traced the pywps code and added the following line, inputXml = inputXml.encode("utf-8") But it gives the following error, 'module' object has no attribute 'parsers'. Whats the wrong in my code? Do any one implemented the pywps with scandinavian letters successfully? Do i need to change anything on pywps part or request xml? Waiting for suggestions, Thanks & Regards, Bala balavignesh <kbalavignesh@gmail.com> writes: > Whats the wrong in my code? Without seeing your code, all we could do is guess, poorly. Far better would be if you can construct a very small example, one that you post here so any reader here could run it, that demonstrates the behaviour you want explained. Don't forget to say what you expect the code to do differently. -- \ “I can picture in my mind a world without war, a world without | `\ hate. And I can picture us attacking that world, because they'd | _o__) never expect i...

Can't cd , can't use wildcard
Hi , I am running Windows 2000 service pack 4.Whenever I try to "cd" into some of the directories(which exist), I get an "Invalid directory". I can use to get into few of the directories(using cd) but for other it just says "Invalid directory". Moreover, I can't use any wildcard characters..(*, ? etc) at all.. Any idea what is wrong? Thanks Arun On Sun, 31 Aug 2003 17:13:52 GMT, Arun Goel <arun.goel@sbcglobal.net> wrote the following to comp.os.msdos.misc: > Hi , > > I am running Windows 2000 service pack 4.Whene...

DVD Won't Enter, Won't Exit
Greetings, all. Long time no see. I have an iMac G5 c. Dec. 2004. A few minutes ago, I inserted a DVD, but it seems not to have mounted in the drive. The disk is just barely too far inside the machine to reach. It's not visible from the outside at all. I've gently tried to insert a second disk, hoping to push the first one all the way in, but it won't budge. I tried restarting the computer with the eject key depressed, and heard the drive trying to eject something, but, again, the disk didn't seem to move. Any ideas, short of reaching in there with a pair of tweez...

4000T won't boot won't POST
I've had this problem for a while. Repair guys (no longer servicing Amiga's) said it was a problem with the motherboard not posting. (I believe this is a PC term) Said he got it working somehow by by-passing SCSI and using only IDE. But when returned it still did not work. Even with a new Power supply, nothing seems to power up. Even the floppy doesn't 'flick' (that funny noise it makes upon power-up) Any help appreciated. thanks Phil "Phil Bastien" <pbastien@nnby.net> ha scritto nel messaggio news:c9qtlu0na3@enews1.newsguy.com... > I've had this problem for a while. Repair guys (no longer servicing Amiga's) > said it was a problem with the motherboard not posting. (I believe this is a > PC term) Said he got it working somehow by by-passing SCSI and using only > IDE. But when returned it still did not work. Are you using an X-Calibur accelerator? It is incompatible with the A4091 and, with my configuration, it hangs just after loading its software, when it resets the Amiga. I am curious about how to bypass the SCSI controller in the A4000T... -- ___ __ / __|___ Daniele Gratteri, Italian Commodore-Amiga user... /// | / |__/ Nickname: FIAT1100D - ICQ: 53943994 Ritmo S75 __ /// | \__|__\ Home page: http://www.gratteri.tk forever! \\\/// \___| E-MAIL: daniele@gratteri.tk ...since 1990 \/// ...

M$ can't create an OS that doesn't get sick from viruses
Read and weep Win### http://www.slashgear.com/microsoft-testing-fix-for-windows-phone-sms-bug-desktop-software-not-immune-29204989/ ...

Aarrrgh!! Why won't this work? (Apologies if this is a dup post- can't find the other)
I have a control on a form whose data source is: =IIf([txtPercentTotal]=1,"Total is 100%",IIf([txtPercentTotal]>1,"Total is Over 100%; Please Adjust",IIf([txtPercentTotal]<1,"Total is UNDER 100%; Please Adjust"))) I have tried =IIf([txtPercentTotal]>1,"Total is Over 100%; Please Adjust",IIf([txtPercentTotal]<1,"Total is UNDER 100%; Please Adjust","Total is 100%")) and =IIf([txtPercentTotal]>1,"Total is Over 100%; Please Adjust",IIf([txtPercentTotal]<1,"Total is UNDER 100%; Please Adjust",IIf([txtPercentTotal]=1,"Total is 100%")) The problem is that I never get the "Total is 100%" message, even when it's 1. I have tried adding the 14 values in Excel and they come to 1.00. I have put the decimal places to 4 and 5 and it's all zeroes. I typed the values into the table and want (ultimately) to enter them via a form. Thanks Sara On 31 Jan 2007 15:22:50 -0800, "sara" <saraqpost@yahoo.com> wrote: Not sure, but why not as an interim step put the value of txtPercentTotal in a field, or enter an expression in the Immediate window like: ?Forms!SomeForm!txtPercentTotal That way you would know for sure what Access thinks is the current value. Then: ?(Forms!SomeForm!txtPercentTotal = 1) Which would result in True or False. If you are using Double data type, it goes to 15 decimals if I'm not mistaken. Your value could be: 1.00000000...

[News] Op/Ed: Microsoft Won't/Can't Assault Linux
The fair-weather "friends of Linux" ,----[ Quote ] | I just finished reading John Carroll's article Why Microsoft won't | assault Linux and while I agree with his conclusion, I don't agree | with his reasoning. John opens up suggesting that a "full legal | assault" on Linux would be self-defeating. I don't think so | but I do think that filing suit against RedHat would be an | unnecessary waste of Microsoft's time and money. | | I would like to dispense with his first point: Patents cut both | ways. While this is certainly true, John assumes that there are | powerful "friends of Linux" who would counter-sue Microsoft in a | heartbeat if Microsoft were to use it's patents against RedHat and | he reminds us that: Nobody has more patents than IBM. `---- http://blogs.zdnet.com/BTL/?p=3924 ...

Can't clean. Says it's printing. It isn't.
I'm trying to clean cartridge heads in an HP660C printer that has been unused for some time. I printed one test page which showed streaks. No other jobs had been set up for printing nor were being printed. When I went to the services page and tried to clean the heads it kept coming up with a message that I can't because the printer is printing. It wasn't. I tried "purge print documents", and turning the printer off and on again. Still wouldn't clean. Thanks for any suggestions. I really need to get some letters printed soon. "Martin" <marty123@optonline.net> wrote in message news:sDY7d.28771$kq6.18831495@news4.srv.hcvlny.cv.net... > I'm trying to clean cartridge heads in an HP660C printer that has been > unused for some time. I printed one test page which showed streaks. No > other jobs had been set up for printing nor were being printed. When I went > to the services page and tried to clean the heads it kept coming up with a > message that I can't because the printer is printing. It wasn't. > > I tried "purge print documents", and turning the printer off and on again. > Still wouldn't clean. > > Thanks for any suggestions. I really need to get some letters printed > soon. > Removed and reinstalled cartridges. Problem solved. Not sure why. ...

mac won't boot...memberd[58] can't find root user
I am not much of a mac user but was given the task of getting postgresql and an application working on a G4. I successfully installed postgresql from the sourceforge package and got this java application running. The only thing I can think that i did other than the postgresql install is that I reset the root passwd. Everything was working great until I rebooted this morning. The gray screen with the apple appears with the progress pinwheel and nothing happens. I was not able to boot into safe mode. I was able to boot in singleuser mode. When I try and startup from there I see this repeate...

Sql Server ODBC applet won't start can't configure problem
Hi, I am trying to add a new ODBC entry for Sql Server, XP Pro. SP2, sqlserver odbc 2.000.8xxxxxxx. All it does when I hit "Add" show the hour glass for a millisecond and then it does nothing. I also had a program that created entries in the background for its use. The program kept failing, so I checked the ODBC entries. This is where I found I could not add. I also could not configure existing ones. (the program has nothing to do with the odbc itself.) In the event viewer is the following: Event Type: Error Event Source: SQL Server ODBC driver support error Event Category: None Event ID: 0 Date: 1/26/2005 Time: 11:23:28 AM User: N/A Computer: MyComputer Description: The description for Event ID ( 0 ) in Source ( SQL Server ODBC driver support error ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Unable to load SQL Server ODBC driver resource DLL. The application cannot continue. .. I can't find anything on this. I can't install the latest MDAC because it says I am already up to date. Does anyone know how to help? Thank you. ...

Register article
Nice article on Microsoft being supplanted by Apple for second place in S&P's list of largest companies for market capitalisation. Says it all, very eloquently. http://www.theregister.co.uk/2010/04/23/microsoft_third_quarter/ So shall we have a minute's silence for Microsoft? Nah: I prefer Muttley-style snickering: http://www.youtube.com/watch?v=UZm47SrmuwM Ian. -- Ian Piper --� On 4/26/10 1:58 AM, Ian Piper wrote: > Nice article on Microsoft being supplanted by Apple for second place in > S&P's list of largest companies for market capitalis...

Maple9 Can't run, can't re-install
-I installed the maple-9 on laptop without any problem. But when I run it, nothing happens. -I tried to uninstall it with start->settings->control panel->add/remove program->maple9, the "add/remove program" freeze (for long--------). All other programs still work at that time (computer is not froozen). -I tried to shut down the computer, it needs to 'end' the 'un-installation' -I tried to re-install the maple9 from the original CD, nothing happens. -With 'autorun', it runs a few seconds and nothing happens. -Tried to installed it ...

Web resources about - Can't seem to create a simple pattern matching function due to character than won't allow me to escape it. - comp.lang.php

Resources last updated: 3/23/2016 9:51:16 PM