Hello everyone,
I'm a PHP newbie and I'm having trouble understanding the pattern syntax in preg_match_all. For example, something like this:
(this pattern looks for image paths on a given url)
preg_match_all(“/src=[\"']?([^\"']?.*(png|jpg|gif))[\”‘]?/i”, $page_data, $images);
can someone please break down what all those characters mean in the pattern?
1) Why is there a “/” forward slash before src
2) What does a “?” mean?
3) what does ^ mean?
4) why is there /i on the end?
5) what are the (, [, ., * and other special characters?
I went through http://de3.php.net/manual/de/reference. ... syntax.php
but its also hard for me to understand...
Understanding $pattern syntax
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Understanding $pattern syntax
It's called a regular expression (often shortened to Regex, or RegExp). Take a look at our "Regex" board here on the forum, then read the first sticky in there named CRASH COURSE Pt 1.