Jump to content

Archived

This topic is now archived and is closed to further replies.

Braet

Newbie regex - need new glasses perhaps?

Recommended Posts

4 hours later and I still can not find where I have gone wrong - nor can I find the answers on my own, so here goes.

My script is not finding matches, the code (well.. in its current incarnation):
[code]preg_match_all("/(.+?) \((.+?)\) \[(.+?)\]\: (.+?)/ims", $winremove, $match3);[/code]

A typical line it will be searching:
Jonathan (729) [Title]: Information, perhaps nothing - perhaps run on sentences

the script will echo $winremove for me - actual echo:
Array[];
Array[];
Array[];
Array[];
Jonathan (729) [Title]: Information, perhaps nothing - perhaps run on sentences.
Array

from this code:
[code]echo <<<TESTMATCH
$match3[1][$i];<BR>
$match3[2][$i];<BR>
$match3[3][$i];<BR>
$match3[4][$i];<BR>
$winremove<BR>
$match3
TESTMATCH;[/code]

As I'm new to PHP (whoohoo, 5 days now!), I'm quite sure I'm falling under the ID10T ways and it's sitting plain as day in the coding above, but for the life of me I can not see it and hope someone here can.

tia!

Share this post


Link to post
Share on other sites
The [tt]$match3[number][$i][/tt] format needs to be changed to [tt]{$match3[number][$i]}[/tt] -- see "Complex syntax" under [url=http://us2.php.net/manual/en/language.types.string.php]strings[/url].

Share this post


Link to post
Share on other sites
ok, I see what you are stating for output - but in case that format was incorrect I also added the $match3 (no info is returning).  What caused me to attempt printing out is that it was not putting the information (once separated) into the db table.  I then set it to print each match, as well as the $winremove variable, and the $match array to see exactly where the issue was.  Changing the echo coding still provides me with a lack of information in $match3 and the variables created from it.

Perhaps I'm just missing something in the information you directed me to, but it seems to me the issue is that it is not finding any matches, there has no data to print (as $match3 should print as $winremove does, no?)

tia!

Share this post


Link to post
Share on other sites
This works for me:

[code]
<?php
$winremove = 'Jonathan (729) [Title]: Information, perhaps nothing - perhaps run on sentences';
preg_match_all("/(.+?) \((.+?)\) \[(.+?)\]\: (.+?)/ims", $winremove, $match3);
echo '<pre>', print_r($match3, true), '</pre>';
?>

[/code]

Share this post


Link to post
Share on other sites
as it does for me, and if I add a little $ in there at the end, it gives me everything I need.  I now officially feel sick that I spent 6 hours focused on the wrong issues - thanks so much, now I can move on to figuring out why it's not going into my db (found 2 other issues based on your info).

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.