Nura111
asked on
PHP syntax
I'm trying to write a script that find a certain link im continue somebody else work and don't really understand what he meant in the following
$pattern = "/<\/?\w+((\s+(\w|\w[\w-]* \w)(\s*=\s *(?:\".*?\ "|'.*?'|[^ '\">\s]+)) ?)+\s*|\s* )\/?>/i"
$pattern = "/<\/?\w+((\s+(\w|\w[\w-]*
Looks like a REGEX pattern. Please tell us what you're trying to find and give us an example of the inputs and the outputs you want. I am sure we can help. ~Ray
The line is pattern of PHP regular expression:
http://www.regular-expressions.info/php.html
http://php.net/manual/en/function.preg-match.php
http://www.regular-expressions.info/php.html
http://php.net/manual/en/function.preg-match.php
ASKER
yes and im trying to understand what this regular expression mean. right now I need to look at the results from the script that somebody else wrote so i need to understand what does he meant by this regular expression.
if you can tell me how to begin to read it,
Thank you!
if you can tell me how to begin to read it,
Thank you!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Afterthought... You will find examples of regular expressions like that one all over the WWW, and many of them are wrong in one way or another. When you start writing your own regular expressions, do it as shown in this code snippet, with separate lines for separate parts and with comments to document the intent of each part of the REGEX. This is a REGEX for validating an email address, something that does not have to be done via REGEX any more, now that we have the PHP function filter_var().
http://php.net/manual/en/function.filter-var.php
http://php.net/manual/en/function.filter-var.php
$regex
= '/' // START REGEX DELIMITER
. '^' // START STRING
. '[A-Z0-9_-]' // AN EMAIL - SOME CHARACTER(S)
. '[A-Z0-9._-]*' // AN EMAIL - SOME CHARACTER(S) PERMITS DOT
. '@' // A SINGLE AT-SIGN
. '([A-Z0-9][A-Z0-9-]*\.)+' // A DOMAIN NAME PERMITS DOT, ENDS DOT
. '[A-Z\.]' // A TOP-LEVEL DOMAIN PERMITS DOT
. '{2,6}' // TLD LENGTH >= 2 AND =< 6
. '$' // ENDOF STRING
. '/' // ENDOF REGEX DELIMITER
. 'i' // CASE INSENSITIVE
;
if (!preg_match($regex, $email)) return FALSE;
ASKER
ok thank you ray, there is anyway that you can five me a regex for finding URL?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok i just want to make sure i understand it right does $urlregex is pattern for the regular url as in http:www.domain.com ? and does it also allows to find URL as name1-name2 pattern? (with -)
Thank you!
Thank you!
Yes, in the example you have seen, $urlregex is the REGEX pattern.
If you are beginner to PHP, I don't recommend you to start with REGEX, since it's more complicated than the other methods in PHP.
If you are beginner to PHP, I don't recommend you to start with REGEX, since it's more complicated than the other methods in PHP.
ASKER
so what is my other options to find a URL in a content not with REGEX?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.