preg_match - How do I...?
Moderator: General Moderators
preg_match - How do I...?
Say I want to find in a string the word 'car' and after that it can be anything any lenght but the word 'hotel' and after that it can be anything any lenght and then the word 'hello' should come.
How would that perl regex look like?? How do I write to not allowing a word like 'hotel' inside this string?
/Andreas
How would that perl regex look like?? How do I write to not allowing a word like 'hotel' inside this string?
/Andreas
You should read up on preg_match(): preg_match ( string pattern, string subject [, array matches]).
Hope thats what you wanted 
Code: Select all
<?php
$string = "the car is parked in the hotel";
if( preg_match("hotel", $string) )
{
echo"hello";
}
?>Nope!
Say I want car --- NOT: parked --- hotel
Try this:
What I want it to match here is:
car run into the hotel
not:
car is parked in the hotel
Say I want car --- NOT: parked --- hotel
Try this:
Code: Select all
<?php
$string = "the car is parked in the hotel, no the car run into the hotel!";
...???
?>car run into the hotel
not:
car is parked in the hotel
Exactly what I want to find is this:
I want it to match first '<a ' then following anything but '</a>' and then anything until 'muppo'
So it would find:
<a href="#">muppo
And not:
<a href="http://www.company.com">test</a>some text<a href="#">muppo
Is it clear?
Thanks!
Andreas
Code: Select all
$text = 'This is a test <a href="http://www.company.com">test</a>some text<a href="#">muppo</a>whackoo!!';So it would find:
<a href="#">muppo
And not:
<a href="http://www.company.com">test</a>some text<a href="#">muppo
Is it clear?
Thanks!
Andreas
Code: Select all
$text = 'This is a test <a href="http://www.company.com">test</a>some text<a href="#">muppo</a>whackoo!!';
if( preg_match("<a href="#"></a>$", $text)
{
echo"true";
}Code: Select all
<?
$text = "This is a test <a href="http://www.company.com">test</a> some text <a href="#">muppo</a> whackoo!!";
if(preg_match("/<a href=(.*)</a>/i",$text,$match)) {
echo $matchї0];
}
?>Isn't ereg slower?
I've heard ereg is slower than preg!?
Is it easier done with ereg?
Is it easier done with ereg?