Reply
What do these mean?
Old 04-17-2007, 09:36 PM What do these mean?
Extreme Talker

Posts: 217
Often when I look through the PHP manual for certian functions, I see things like this:
PHP Code:
 <?php
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i',
    
"http://www.php.net/index.html"$matches);
$host $matches[1];

// get last two segments of host name
preg_match('/[^.]+\.[^.]+$/'$host$matches);
echo 
"domain name is: {$matches[0]}\n";
?>
I know what it does, and have used it, but one thing I dont understand is this: /[^.]+\.[^.]+$/ or @^(?:http://)?([^/]+)@i (from the example above. ONly part I really understand of those is that the i means case insensitive.

Iv looked through the manual but cant seem to find anything
__________________
Helm Games
Slick Nick is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 04-17-2007, 10:05 PM Re: What do these mean?
Republikin's Avatar
Super Moderator

Posts: 3,191
http://regexlib.com/CheatSheet.aspx

This will tell you what each character means so you can start to decipher the above regex.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 04-18-2007, 12:27 AM Re: What do these mean?
mtishetsky's Avatar
King Spam Talker

Posts: 1,056
Name: Mike
Location: Mataro, Spain
The second one means "many not-a-dots, then dot, then again many not-a-dots at the end of the line". The first one is too complicated for me though I understand what it does. But I would do the same thing in another way.
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 04-18-2007, 01:07 AM Re: What do these mean?
Extreme Talker

Posts: 217
thanks guys, been helpful.

Im trying to modify the code i showed in my OP so that it grabs the entire url, not just the host/http. So far, no dice. Any help?
__________________
Helm Games
Slick Nick is offline
Reply With Quote
View Public Profile
 
Old 04-18-2007, 02:10 AM Re: What do these mean?
mtishetsky's Avatar
King Spam Talker

Posts: 1,056
Name: Mike
Location: Mataro, Spain
What entry data do you have and what do you want to obtain from it?
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 04-18-2007, 10:03 AM Re: What do these mean?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,322
Name: Keith Marshall
Location: West Hartford, CT
http://www.regular-expressions.info/
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 04-18-2007, 07:29 PM Re: What do these mean?
Extreme Talker

Posts: 217
Quote:
Originally Posted by mtishetsky View Post
What entry data do you have and what do you want to obtain from it?
Say somebody posts a URL in their comment, I want to be able to grab that url and turn it into a link.
__________________
Helm Games
Slick Nick is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to What do these mean?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13404 seconds with 12 queries