...

View Full Version : error massage



kamkam
08-31-2007, 11:07 AM
Hi;
Could anyone debug for me, please.

Warning: preg_replace() [function.preg-replace]: Unknown modifier 'a' in index.php on line 6

my code as following;



<?php //line 1

$str=' test & me ';
$p='^[^a-z]+$';
$r='_';
$str=preg_replace($p, $r, $str); // here is line 6
echo $str;

?>

Mwnciau
08-31-2007, 11:42 AM
When you use preg_replace you need to start with a character and end with the same character and put any modifiers after the end character.

eg.


preg_replace('#hi#', 'hello', $text); // Replaces hi with hello using # as the start and end
preg_replace('`hi`i', 'hello', $text); // Exactly the same but the i after the ` makes the match insensitive
preg_replace('#hi\##', 'hello', $text); // Replaces hi# with hello, the # has to be escaped because it is the start and end character


More info in regular expressions help in my sig.




<?php //line 1

$str=' test & me ';
$p='#^[^a-z]+$#';
$r='_';
$str=preg_replace($p, $r, $str); // here is line 6
echo $str;

?>

kamkam
08-31-2007, 12:02 PM
Thanks, the compiler does not complain now.

And if i want to replace all the chars which >=1, without a-z, by using '_', how i can do that. my code does not work for this. Could you help, please.

for example;
' test & me ' -> '_test_me_'

Mwnciau
08-31-2007, 12:26 PM
<?php //line 1

$str=' test & me ';
$p='#[^a-zA-Z]+#';
$r='_';
$str = preg_replace($p, $r, $str); // here is line 6
echo $str;

?>

That works fine for me.

kamkam
08-31-2007, 12:45 PM
Thanks a lot, it does work now.

but where about the following, would you give me a link, please.



More info in regular expressions help in my sig.

Mwnciau
08-31-2007, 12:56 PM
Regular Expression Help (http://www.regular-expressions.info/)

kamkam
08-31-2007, 01:46 PM
Thanks a lot



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum