Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Regular expressions, URL specification

ereg or other function? What kind of urls ar best?

3:21 pm on Jul 2, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 11, 2005
votes: 0

I've got 2 questions:

1. I use php to have the root level of my site be the only place for users to be able to read. They can only see the images and media (for .swf and .css) But they won't get any listings. But back to the question,
Should I continue to use urls like this one:


The scipt returns the requested page or thge defult one, but are such links the right way to go? W3c says text links explaining the content are the best ones, but they should be flexible so if the file has been moved in the filesystem it is still alvailible via the same link.
So, should I follow the w3c guidelines or not this time?


I can't find a good place to learn how to use the ereg() php function, and I've heard the "perl one" is better and included in php, and ereg should not be used? I don't know what to search for or to chose. At this time I am doing character filtering useing some code lines for each unallowed thing like "," or "`" etc.


$name0 = str_replace(",", "", $name);
$name1 = str_replace(" ", "", $name0);
$name2 = str_replace("'", "", $name1);

This isn't the right way but I can't help it, I don't know enough to use ereg or the other function to match a pattren.

John Keates (from Holland, that's why the bad english...)

6:13 pm on July 2, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 29, 2005
votes: 0

English not too bad. Incidentally there used to be an English poet by the name of John Keats (may be you alreay know that) :)

the php manual says "preg_match(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to ereg()."

its more important to get the regexes right. once that is in control everything works neatly.
try this site: [regexplib.com...]

sorry couldnt be of any more help than this. hope you get the help you are looking for.

6:30 pm on July 2, 2005 (gmt 0)


WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
votes: 236

1. Whether or not I use intelligent, clean, technology-independent URLs depends on the site, but in general, if it's a public site that's expected to be around for a while, I try very hard to use URLs that make sense as part of the interface and are more or less human readable. Now that SEs will read query strings, it has very little meaning there. Interestingly, I read an article by one of IBMs usability experts who said that in all their tests, they had never come across a user who tried to navigate by editing a URL. I guess that's just a few of us geeks who do that.

So those two things taken together say that for most purposes, there isn't much to gain by worrying about your URLs. That said, I think that
- it's one of those little design things that gives a little polish
- as the web user base becomes more savvy, users who perceive the URL to be part of the interface will be more numerous and the benefit will increase.

2. str_replace() can take an array as an argument, so one easy way, would be

$array = array(',', ';', '#', '*');
$new = str_replace($array, "", $old);

That works well if you have a small black list of unallowed characters. If you want a white list approach, regex is probably better,

$pattern = '/[^a-zA-z0-9_-]/';
$new = preg_replace($pattern, "", $old);

This will get rid of anything that is not on your white list.

2:43 pm on July 3, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 11, 2005
votes: 0

Many, many thanks to you both!

The regex thing was what I was searching for!
And if the only people that are navigating through urls are people like us, I don't think I will replace the page indentifyer. Numbers are smaller to make an url with, and the database if optimized to use them, plus it is easyer for me to program this ;-)

John Keats is somewhere connected to my family, don't know where but, somewhere I know.

John Keates

10:07 pm on July 3, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 17, 2003
votes: 0

The search feature has been disabled so I did not see this message...

I also want to replace the id number with something readable / descriptive of the page.

Where would this:

$pattern = '/[^a-zA-z0-9_-]/';
$new = preg_replace($pattern, "", $old);

work in this code:

$sql = mysql_query("SELECT id, author, title FROM articles ORDER BY id ASC");

if ($myrow = mysql_fetch_array($sql)){


echo "<table class=table_general cellpadding=0 cellspacing=5>";

do {

printf("<tr bgcolor=#55556F><td valign=top width=150><b><a href=%s?id=%s>%s</a></b></td><td><div align=justify>%s ... <br><br><font color=#FFFF00>[<b><a href=%s?id=%s title=%s>READ FULL DEFINITION</a></b>]</font></div></td></tr>\n", "article.php", $myrow["id"], $myrow["title"], $myrow["author"], "article.php", $myrow["id"], $myrow["title"]);

Thank you in advance for taking the time to answer my question.



Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members