|
-
Jan 17th, 2004, 02:28 PM
#1
Thread Starter
Member
preg_match_all, and whitespace
How do I make this code work no matter how much space is inbetween the html tags?
Code:
$template = '<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td><h1>(.*)</h1></td><td align="right"> </td></tr></table>';
preg_match_all("|".$template."|U", $copy, $system);
Doesn't work if the text appears like
Code:
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td><h1>BLAH HAHA!</h1></td>
<td align="right"> </td>
</tr>
</table>
I'd like to keep the PHP on a single line, just so it takes up less space
-
Jan 17th, 2004, 03:14 PM
#2
Stuck in the 80s
Did you try using the 'x' modifier? I believe that ignores all whitespace.
-
Jan 17th, 2004, 03:32 PM
#3
Thread Starter
Member
:/
tried it, but it doesn't change anything
-
Jan 19th, 2004, 04:56 AM
#4
Then you'll have to change the template. I think \w matches a whitespace, so put \w* everywhere where there might be whitespace. And that's a lot of places 
It's not pretty.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 29th, 2004, 08:24 PM
#5
Thread Starter
Member
ok, got the problem figured out and all...
but.. using preg_match_All, it's weird..
$img[1][1]
$img[1][2]
$img[1][3]
Grabs correctly, but it SKIPS the first instance of the found string..
(Say i'm looking for the word "Hi", I only need that word 3 times.. but there are only 3 instances of the word, in the text.
The FIRST two variables will be "Hi".. the third will be EMPTY. It's skipping the first instance of the string to be found..
if I do:
$img[1][0]
$img[1][1]
$img[1][2]
The LAST two are "Hi".. but the first one is a WHOLE LOT more text than I specified to search for.. but the second variable *IS* the second instance of "Hi" and the third IS the THIRD instance of "Hi"
So.. something is really weird.. and I have no idea what's wrong with it.... Any suggestions?
BTW: I'm using non-greedy statements (matches as little text as possible)
-
Jan 30th, 2004, 01:10 AM
#6
Thread Starter
Member
when i do
$img[1][0]
it seems to be grabbing TOO MUCH.
but I have the greediness OFF... but it's still grabbing too much
i don't understand.. in my expression, are there any non-literal characters that i forgot to escape?
-
Jan 30th, 2004, 05:19 AM
#7
Arrays start with 0. But for regexp matches, [0] is the whole input string. What about $img[0][n] ?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 10th, 2004, 04:03 PM
#8
Thread Starter
Member
$img[1][0] -- Too much.. or whatever..
$img[1][1] -- Is actually the SECOND image on the page
$img[1][2] -- Is the THIRD image on the page
-
Feb 10th, 2004, 04:25 PM
#9
You sure your expression captures the first image?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 15th, 2004, 03:18 PM
#10
New Member
To keep a string on a single line use this...
PHP Code:
Function sameLine($string)
{
$string = str_replace("\n","",str_replace("\r","",$string));
return $string;
}
-
Feb 18th, 2004, 10:24 PM
#11
Thread Starter
Member
Originally posted by CornedBee
You sure your expression captures the first image?
yes, most definitely, it does...
All the images are setup the same, on the pages i'm grabbing the html from...
To keep a string on a single line use this...
I use something similar, and so yes, everything is on a single line, but the code still seems to capture too much, the first time..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|