homepage Welcome to WebmasterWorld Guest from 54.166.108.167
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Regular expressions, URL specification
ereg or other function? What kind of urls ar best?
John_Keates




msg:1262129
 3:21 pm on Jul 2, 2005 (gmt 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:

www.mysite.com/?p=45

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?

2.

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.

Code:

$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...)

 

maxi million




msg:1262130
 6:13 pm on Jul 2, 2005 (gmt 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.

ergophobe




msg:1262131
 6:30 pm on Jul 2, 2005 (gmt 0)

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.

John_Keates




msg:1262132
 2:43 pm on Jul 3, 2005 (gmt 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

alcheme




msg:1262133
 10:07 pm on Jul 3, 2005 (gmt 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)){

$id=$myrow["id"];
$insert_date=$myrow["insert_date"];
$author=$myrow["author"];
$title=$myrow["title"];

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.

~Shane

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved