Jump to content

Can;t get this statement?


siddscool19

Recommended Posts

Can someone please tell me how to use url in a preg_match

When i was writing code:

preg_match("http://rapidshare.com/",$link,$rs);

It gave me following error:

 

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\xampp\htdocs\rs\2.php on line 35

 

What should i do to remove this error?

 

Also i want to know how to get a particular part of a line in the array using preg_match

Link to comment
Share on other sites

Yes, the dot is a metacharacter that matches anything that is not a newline. So in your example:

preg_match('%http://rapidshare.com/(.*)%', $line, $rapidurl);

 

The pattern first will be required to match the following characters in sequence:

http://rapidshare.com/ (ah.. be careful about that dot in the url.. in this case, the regex engine is not looking to match a dot, but again, any character that is not a newline chartacter.. you will need to escape that dot (\.)

 

So then, assuming all of this matches, your (.*) will continue on matching anything that is not a newline character. Very straight forward stuff.

 

I agree with the moderator.. best to look stuff up in the php.net manual. There is a text field along the top that allows you to type in any function or language construct and the manual will point you to the right place (assuming you spelled it correctly)

Link to comment
Share on other sites

Can u please tell me how to get a particular part of a line using preg_match?

One more thing whats the use % ?

One more thing whats a new line character i guess its \n am i right?

 

The % character is called delimiter (you need delimiters in your Perl Compatible Regular Expressions (which is what PHP uses)).

I can tell you are the kind of person who wants to learn by taking initiatives and accepting any help others offer.. so I point to this link as a tutorial on PCRE:

 

http://devzone.zend.com/node/view/id/1247

 

Please take the time to review this link.. it will help you out with the basics. At this point, don't worry about 'how to get a particular part of the line using preg_match'.. I would focus on the basics and build from there.. then you will actually understand the code you are working with. Trust me, it will pay off in the long run.

 

Cheers,

 

NRG

 

EDIT.. I noticed some of the links in the link I posted don't seem to be working, but at least the top half of the site should be helpful in getting you started. I'm sure other mods / members can provide some other links as well (as kenrbnsn has done).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.