Results 1 to 8 of 8

Thread: [RESOLVED] PHP - "Regular Expression?"

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Resolved [RESOLVED] PHP - "Regular Expression?"

    Is here any code to download information & words from different website?

    Like Regex in VB.NET?

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: PHP - "Regular Expression?"

    Yes. PHP has a regular expression matching system. Lookup the function preg_match on the PHP homepage for example.
    My Blog.

    Ryan Jones.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: PHP - "Regular Expression?"

    Thanks for information i tried it, but i don't understand it, because 99% what i found was for e-mail.

    Can you give one example for some website?

    Thanks.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP - "Regular Expression?"

    the preg_match() function in the PHP manual does not have anything about email. I'm not sure what you were looking at, but surely you were not looking in the manual (as was suggested).

    either way, the regular expression engine in PHP uses PCRE (Perl Compatible Regular Expressions), and you can learn more about them here. they really have little to do with any language and might even be considered a language of their own. I'd suggest playing around with them on test files/test strings to get the hang of it before trying to efficiently parse an entire website.

    however -- regular expressions have nothing to do with what you were asking for in your original post ("download information and words from a different website"). the preg_match() function can help you parse strings, but it cannot "download information." you would need to use another function to fetch information. you could use the standard file opening functions (fopen() or file_get_contents()) as long as the allow_url_fopen directive is enabled in your PHP install, or you could opt for an extension such as cURL. once you've fetched the data, you can use preg_match() to parse it using a regular expression.
    Last edited by kows; Dec 31st, 2009 at 11:32 PM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: PHP - "Regular Expression?"

    Quote Originally Posted by kows View Post
    the preg_match() function in the PHP manual does not have anything about email. I'm not sure what you were looking at, but surely you were not looking in the manual (as was suggested).

    either way, the regular expression engine in PHP uses PCRE (Perl Compatible Regular Expressions), and you can learn more about them here. they really have little to do with any language and might even be considered a language of their own. I'd suggest playing around with them on test files/test strings to get the hang of it before trying to efficiently parse an entire website.

    however -- regular expressions have nothing to do with what you were asking for in your original post ("download information and words from a different website"). the preg_match() function can help you parse strings, but it cannot "download information." you would need to use another function to fetch information. you could use the standard file opening functions (fopen() or file_get_contents()) as long as the allow_url_fopen directive is enabled in your PHP install, or you could opt for an extension such as cURL. once you've fetched the data, you can use preg_match() to parse it using a regular expression.
    Yes, but there is no example for another website. I hate those $pattern etc things. Would be just as it is without $things. Makes me confused a bit.

  6. #6
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: PHP - "Regular Expression?"

    As kows has said. You would first need to read the contents of the website. Then the regexp you would you depended on what you would like to extract from the web page. Can you be more specific as to what you are looking to extract?
    My Blog.

    Ryan Jones.

  7. #7

    Re: PHP - "Regular Expression?"

    Can any one tell me what will be the regular expression for EmailID. If we are using Mobile Number field then what type of variable we should take for to save mobile number.

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP - "Regular Expression?"

    ... this.. has nothing to do with regular expressions?

    a mobile number would be a string; you want to probably store spaces and possibly parenthesis for an area code rather than having a long integer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width