i dont understand how i can use this...use eregi_replace() or preg_replace() with the /i modifier instead
can some explain how this would work if my variables are $search, $replace and $text?
| SitePoint Sponsor |



i dont understand how i can use this...use eregi_replace() or preg_replace() with the /i modifier instead
can some explain how this would work if my variables are $search, $replace and $text?
hmm...





Hi!
The /i modifier stands for case insensitive. Capitalization and small letters are ignored.
So searching for
$var = "search";
preg_match("/SeArCh/i", $var);
would match.
preg_match("/SEARCH/", $var);
instead would not.



so would preg_replace(/$search/i,$replace,$text) work?
hmm...





At a guess I would say so. Not absolutely sure, though.



does any body know how i could do it using $search as the search string, $replace as the replacement string and $text as the string being searched?
hmm...





This searches the variable text for the contents of the variable $search and replaces it with the contents of the variable $replace
$text = preg_replace("/$search/i",$replace,$text);
Or do you want to search for "$search" ie finding the dollarsign and then the word sign?



i keep getting this error:
Warning: Compilation failed: unmatched parentheses at offset 1 in /home/randompc/public_html/mumblingjoe/inc/functions.inc on line 109
Warning: Compilation failed: missing ) at offset 2 in /home/randompc/public_html/mumblingjoe/inc/functions.inc on line 109
code (109 is the preg_replace() line):
PHP Code:$text = stripslashes($text);
$text = str_replace("\n","<br>",$text);
if ($smilies == "1") {
$sql = "SELECT * FROM smilies";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$search = $row[emoticon];
$replace = $row[smilie];
$replace = "<img src = [url]http://mumblingjoe.randompc.com/img/smilies/[/url]$replace>";
[b]$text = preg_replace("/$search/i",$replace,$text);[/b]
}
}
hmm...





There are several characters that have a special meaning when using regexp.
Some of them are \ ( ) [ ] . ? * + { } |
Since you are searching for emoticons that look probably like this![]()
![]()
you have to escape them in the search string.
So to search for "" the variable $search must be ":\)"
You have to escape every character mentioned above with a "\" then it should work.





To save you a bit trouble try this for the line:
old: $search = $row[emoticon];
new:PHP Code:$search = preg_quote($row['emoticon']);



thanks alot
ive finally got it to work properly
i was just gonna ask you about the preg_quote thingy aswell hehe![]()
hmm...
Bookmarks