Forum Moderators: coopster

Message Too Old, No Replies

Strange PHP Error

Please Help - Urgent

         

erikcw

4:51 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



Hi all,

I'md getting this error:


Warning: Delimiter must not be alphanumeric or backslash in /home/lybp/public_html/members/inc/matching.inc.php on line 80

Here is the code block (line 80 in the preg_replace line)


if ($_POST['remove'] == "1") {
// $find = strtolower($_POST['find']);
$find = explode("\n", trim($negative));

foreach($find as $v) {
$v = quotemeta($v);
$v = "/([^\n]*$v.*)\n/Ui";
}
//$pattern = $find;
//$pattern = "/([^\n]*\b$find\b.*)\n/Ui";
// $pattern = "/([^\n]*$find.*)\n/Ui";
//preg_match_all($pattern, $keywords . "\n", $matches);
//print_r($matches[1]);
// $output = implode("\n", $matches[1]);

$pattern = $find;
//Remove peeled terms from list.
$REPLACEMENTS = "";
$keywords = preg_replace($pattern, $REPLACEMENTS, $keywords . "\n");
}

I have never seen this error before. Can anyone tell me what I am doing wrong?

Thanks!

Sarah Atkinson

4:55 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



I may be wrong on this but don't varriables have to start with a lower case letter?

Sarah

Sarah Atkinson

4:59 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



also the . "\n" might be throughing it off as well

jatar_k

5:00 pm on Jun 23, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



in that particular example

$keywords = preg_replace($pattern, $REPLACEMENTS, $keywords . "\n");

$pattern is equal to $find and $find is an array resulting from your explode

you can't use the array as your pattern

erikcw

5:03 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



Accordng to example 3, [us2.php.net...] you can use an array for patterns...

Could it be something elso or is this an error in the manual?

If you can't infact use an array - how can I accomplish the above task otherwise? (check replace array af patterns in string)

[edited by: erikcw at 5:04 pm (utc) on June 23, 2005]

Sathallrin

5:03 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



I may be wrong on this but don't varriables have to start with a lower case letter?
They do not, it is only a recomended practice that you do that so your code looks nicer.

[edited by: Sathallrin at 5:09 pm (utc) on June 23, 2005]

breezeman

5:05 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



I also read that the pattern in preg_replace should have a / at the beginning and end

gliff

5:06 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



Your pattern isn't valid.

The first argument you pass to the preg functions is the regular expression pattern. This is what you're searching for.

Patterns need to be put in-between (delimited by) two special characters. Traditionally, theses have been forward slashes

/stuff to search for/

But can be a variety of non-alphanumeric not-backslash characters

{foo}
¦bar¦
^hi there^

For some reason, the preg function can't figure out what your delimiters are.

What's inside the $pattern variable when preg_replace runs?

jatar_k

5:07 pm on Jun 23, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> you can use an array for patterns

you are quite right erikcw, my mistake, see I'm not always right, hehe

each pattern needs a delimiter at the front and back so you will need to walk your array and add them

erikcw

5:31 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



I am using this code to create the pattern


$find = explode("\n", trim($negative));

foreach($find as $v) {
$v = quotemeta($v);
$v = "/([^\n]*$v.*)\n/Ui";
}

The foreach loop should be adding the /blah/ to each of the valuse in the array. (note this pattern does work when not used in array form, I barrowed it from another script of mine...)

erikcw

4:07 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Does anyone know what is wrong with this code?


$find = explode("\n", trim($negative));

foreach($find as $v) {
$v = quotemeta($v);
$v = "/([^\n]*$v.*)\n/Ui";
}

jatar_k

4:31 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



funny, I had never seen the function quotemeta until right now

I realize that isn't helpful but

maybe look at the input after each step to see if you can see what is happening

foreach($find as $v) {
echo '<p>orig: ',$v;
$v = quotemeta($v);
echo '<br>after qm: ',$v;
$v = "/([^\n]*$v.*)\n/Ui";
echo '<br>end: ',$v;
}

that might give you a hint

Philosopher

4:53 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also remember that quotemeta doesn't escape the pipe character. Not sure if that is in your array, but if it is, that may cause some problems.