Hello,
I need help with a little problem.
I'm wanting to only display a certain piece of information if the url matches.
For example if the url is http://www.mysite.com/news/news-112.html it will echo Correct
However if the url is http://www.mysite.com/news/cat-112.html it will echo incorrect.
The bit it picks up on will be the news- or cat-.
I've been told to use RegEx and URL but i can't find much information on how to create this.
Any examples or help would be really appreciated.
Thank You
Martin
RegEx URL
Moderator: General Moderators
Re: RegEx URL
You could use parse_url() to get the part of the URL youre interested in, then do the if-then-else on that.
-
Martinc126
- Forum Newbie
- Posts: 2
- Joined: Sun Feb 24, 2008 11:18 am
Re: RegEx URL
Thanks but it's not working like i need it to.JAM wrote:You could use parse_url() to get the part of the URL youre interested in, then do the if-then-else on that.
Basically i need it to
pick out .com/news/news- and echo correct.php
Pick out .com/news/cat- and echo wrong.php
The bit after news- and cat- will change depending on the page the visitor is view.
Martin
Re: RegEx URL
Tried using substr() and other functions to it? I wasn't trying to imply that parse_url() was the only function you needed.
Example;
You don't even have to use parse_url() and so forth if that is to difficult or lacking usefullness to use in your case. Check ereg()/preg() and the section about regular expression in general. There is alot of examples in the comments.
Example;
Code: Select all
$url = 'http://www.mysite.com/news/cat-112.html';
$array = parse_url($url);
echo substr($array['path'], 0, 10);