Jump to content

Newbie regex - need new glasses perhaps?


Braet

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!
Link to comment
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!
Link to comment
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]
Link to comment
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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.