[PHP] PHP RegExp and HTML tags attributes values etc...
Hello ppl, I have a question about regex and html parsing. I have the following code: --- --- It laks some quotemarks. I want to change it to: --- --- So it will have " around the attribute values... But i can't figure out how to do that :(. Can anyone help me with this?? Thx in advance. Kind Regards, BlackDex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
"Eli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Eli wrote: >> >> Try: >> >> preg_replace('/(?<=\<)([^>]*)(\w+)=(?\s]+)(?=\s|\>)([^<]*)(?=\>)/U','\1\2="\3"\4',$html); >> Hmm.. that could be a >> start.. and don't ask me how it works... :P > > Well.. problem with that, is that if you got more than 1 un-escaped attribute > in a tag, the regex will fix only the first > un-escaped attribute. > > for example, if $html is: > style='font-size:12.0pt;font-family:"Comic Sans MS"'> > > In that case the id=par will remain as is... > Does anyone knows how to improve it? First of all thx :). Just an idea... (Becouse im not that good at it). Is it possible to create a while loop for the whole <> part? Simply sad... while <.*?> do { parse the contents of that tag in someway and change it? } Becouse i think it is imposible with RegEx alone to make it so that it can handle every attribute within a tag. Ltrz BlackDex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
"Eli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Eli wrote: >> >> Try: >> >> preg_replace('/(?<=\<)([^>]*)(\w+)=(?\s]+)(?=\s|\>)([^<]*)(?=\>)/U','\1\2="\3"\4',$html); >> Hmm.. that could be a >> start.. and don't ask me how it works... :P > > Well.. problem with that, is that if you got more than 1 un-escaped attribute > in a tag, the regex will fix only the first > un-escaped attribute. > > for example, if $html is: > style='font-size:12.0pt;font-family:"Comic Sans MS"'> > > In that case the id=par will remain as is... > Does anyone knows how to improve it? Just looking at the online mailinglist.. checkout this link, mabye it can help.. http://marc.theaimsgroup.com/?l=php-general&m=97975368123802&w=2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
Thx... it works almost :P I Changed the code a bit so you can see the results quicker :). It doesn't change every attribute/value. I think this has to do something with the opening and closing of a tag <>. My code: --- http://www.php.net/index.php> key=value "; echo 'Normal HTML:'; echo $html; echo ""; $improved_html = preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html); echo 'Improved HTML:'; echo str_replace("\\'","'",$improved_html); echo ""; ?> --- "Eli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Sorry for the spam.. here it is: > > function tag_rep($tag) > { >return > preg_replace('/(? } > > $html=" lang=NL style='font-size:12.0pt;font-family:\"Comic Sans MS\"'> href=http://www.php.net/index.php> key=value "; > > $improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html); > echo str_replace("\\'","'",$improved_html); > ?> > > :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP RegExp and HTML tags attributes values etc...
"Jason Petersen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, 10 Mar 2005 00:18:05 +0100, BlackDex <[EMAIL PROTECTED]> wrote: >> Hello ppl, >> >> I have a question about regex and html parsing. >> >> I have the following code: >> --- >> > style='font-size:12.0pt;font-family:"Comic Sans >> MS"'> > > I'm guessing that you're writing a function to parse "HTML" that users > upload via a web form? I would start with a look at this Perl script > to fix code generated by MS products: > > http://www.fourmilab.ch/webtools/demoroniser/ > --- Il go and check it out.. --- > Also, PHP's "libtidy" extension might be useful for you, although I > haven't used it personally. --- I have tryed it.. But it removes/changes to much even if i disable all the tidy settings. So thats not an option :(. --- > > http://us2.php.net/manual/en/ref.tidy.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
Owkay.. i fixed it :). Here is the final code. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
Owkay i fixed it :D. The regexp needed a /s (Pattern Modifier) also so that the "."(DOT) also does newlines :). Now it is fixed... Thank you very much Eli :) /me is happy. THE CODE: --- http://www.php.net/index.php> key=value "; echo 'Normal HTML:'; echo $html; echo ""; $improved_html = preg_replace('/\<(.*)\>/Ueis','"<".tag_rep("\1").">"',$html); echo 'Improved HTML:'; echo str_replace("\\'","'",$improved_html); echo ""; ?> --- "BlackDex" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thx... it works almost :P > > I Changed the code a bit so you can see the results quicker :). > > It doesn't change every attribute/value. I think this has to do something > with the opening and closing of a tag <>. > > --- > > "Eli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> Sorry for the spam.. here it is: >> >> > function tag_rep($tag) >> { >>return >> preg_replace('/(?> } >> >> $html="> lang=NL style='font-size:12.0pt;font-family:\"Comic >> Sans MS\"'>> href=http://www.php.net/index.php> key=value "; >> >> $improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html); >> echo str_replace("\\'","'",$improved_html); >> ?> >> >> :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Tried to run PHP as shell script and got the error...
Try to put this at top. !/usr/local/bin/php so change the # for a !, becous thas is what is used to execute scripts etc.. :). Hoop it will work. Kind Regards, BlackDex "Scott Fletcher" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi! I'm trying to run PHP as a shell script but I got the error message... > Source code below is ... > > --snip-- > #/usr/local/bin/php >echo "Hello World!!\n"; > ?> > --snip-- > > Attempt to run the file below and got the error > > --snip-- > -=[/usr/local/bin]==>./ecbi_inquiry_pull_experian.sh > Hello World!!\n > ./ecbi_inquiry_pull_experian.sh: line 4: syntax error near unexpected token > `?>' > ./ecbi_inquiry_pull_experian.sh: line 4: `?>' > --snip-- > > I checked to see if there's no spaces at the end on line 4 and there > isn't... So, how do I get it working so I can hook up the file to the > crontab. > > Thanks, > FletchSOD -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_replace with rawurlencoded?
I have a litle problem with replaceing a string in some HTML code. the html code is: --- --- I want to change the "01%20-%20Raptor%20AMD%20Sempron_image001.jpg" becouse the location of the file will be changed after the upload. the location for instains will be "/images/uploaded/01%20-%20Raptor%20AMD%20Sempron_image001.jpg" After the upload i have moved the image to the right location, and i can access it trough the browser. How can replace that string so that it will point to the right location? I tryed a few preg_replace options, but i doesn't changes it. I think this is becouse of the urlencoded string. Does someone has en example? The filename i get trough the $_FILE['userfile'] variable. Thx in advance. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php