PHP - Help With Php's Pcre Patterns
Hey everyone!
New member here still getting the hang of PHP. Any help is much appreciated. Suppose the array contains: array ('http://www.php.net/styles/site.css', 'http://www.example.com/styles/some.js', 'http://www.domain.net/styles/hey.php'); How do I get php to find the array item that contains let's say "css" and instead of returning just "css" it returns the entire string that has the "css" in it, instance "http://www.php.net/styles/site.css". I was thinking of using the following: preg_match('/[SOME_PCRE_PATTERN].css/', 'http://static.php.net/www.php.net/styles/site.css', $matches); Problem is since the links could be different and have all sorts of different characters in it, I have no idea what to put for the PCRE_PATTERN. In other words, this: $links = array ('http://www.php.net/styles/site.css', 'http://www.example.com/styles/some.js', 'http://www.domain.net/styles/hey.php'); foreach ($links as $key) { preg_match('/css/', $key, $matches); $results[] = $matches; } print_r ($results); Returns this: Array ( [0] => Array ( [0] => css ) [1] => Array ( ) [2] => Array ( ) ) I would like it to return: Array ( [0] => Array ( [0] => http://www.php.net/styles/site.css ) [1] => Array ( ) [2] => Array ( ) ) I hope that makes sense to you guys. Once again, any help is appreciated and thank you! Similar TutorialsCreating my own little MVC framework to understand it better. Question - When a view outputs a page with a form in it, how is the form handled? ie, what is the action of the form? Where does the IF statement that checks if the submit button was pressed, go? I was told inside a method in the Model...but I don't understand how a method can check if a form has been submitted or not. Any help greatly appreciated. Hey guys, I have been programming for a while and I want to know what sort of design patterns I should look into when making a game? For example what design pattern is best for: Database management User management Forum management Etc I can only think of singleton or factory (for user/forum) I am reasonably new to OOP, but would like to learn it properly, so I thought creating a simple program such as rock-paper-siccors would work to be able to expand it eventually, and hopefully it will teach me reusable code practice. <input type="text" maxlength="5" name="zip" value="Zip Code" pattern="(\d{5})?" />So, if the zip code is filled, it should be a five digit number. If it's not filled it's optional. The above RegEx is forcing everyone to enter a zip code. Can HTML do this, or am I going to have to script it? |