search for something in a string
Moderator: General Moderators
search for something in a string
I wonder how I can search for some thing in a text string for example: how do I search for all <IMG> taggs? Because the <IMG>-tag contains diffrent things each time I can't use the stristr() function.
Anybody got a suggestion?
Anybody got a suggestion?
Regular Expressions are what you want. I don't want to write you one, because
a) You wouldn't learn
b) I really suck at writing regexes
Functions are at http://ww.php.net/regex
a) You wouldn't learn
b) I really suck at writing regexes
Functions are at http://ww.php.net/regex
I found this example on the page posted.
it just what i want. BUT, there is one thing. i understand that where \\0 som text is posted, but i dont see where it is declared what text will be showed where the \\0 is.
Code: Select all
<?php
$text = ereg_replace("[[]]+://[^<>[]]+[[]/]",
"<a href="\\0">\\0</a>", $text);
?>Thanks!
Thanks alot! Now my page has got better. Thanks to you guys!
I will have a closer look at the regular expressions. they seems intresting
I will have a closer look at the regular expressions. they seems intresting
ewwwwwwwwwwwwww!!!!!!!!!!!!!! don't use ereg here!!!!!!!
ere is posix and therefore a forced greedy. there are times that will backfire. you need perl so you can do non-greedy.
trust me, i already went through finding it out on my own: http://people.brandeis.edu/~m3rajk/JMT/ ... c-fcv4.php
ere is posix and therefore a forced greedy. there are times that will backfire. you need perl so you can do non-greedy.
trust me, i already went through finding it out on my own: http://people.brandeis.edu/~m3rajk/JMT/ ... c-fcv4.php
php has functions that use the perl regular expressions instead of the posix ones.
by greedy i mean that if you have someone accidentally type:
blah blah<img src="url">blah blah >and some more stuff
then it will pick up: <img src="url">blah blah >
perl has a non-greedy method. using the preg_replace instead of ereg_replace you can specify non-greedy so it will then correctly pick up: <img src="url">
by greedy i mean that if you have someone accidentally type:
blah blah<img src="url">blah blah >and some more stuff
then it will pick up: <img src="url">blah blah >
perl has a non-greedy method. using the preg_replace instead of ereg_replace you can specify non-greedy so it will then correctly pick up: <img src="url">