PHP - Moved: Help With Regexp
This topic has been moved to PHP Regex.
http://www.phpfreaks.com/forums/index.php?topic=347542.0 Similar TutorialsEDIT! I just figured out that RegExp has it's own Forum. I apologize! I have decided it may be quicker to seek help with this particular problem. I really, really, really hate regexp with a passion. It's one thing for JS, another for PHP, and for some reason I just can't seem to get them set up to do what I want properly. So I'm just going to leave it up to people who probably have more experience with them or just all around smarter than I am. Here is a list of RegExp that I am using and what it is "SUPPOSED" to do. Code: [Select] <?php // Check username to make sure it only has Letters and Numbers preg_match("/^[-a-zA-Z0-9]+$/", $uname); // Check Password to make sure it has 2 Numbers preg_match("/(.*[0-9].*[0-9])/", $pass); // Check Password to make sure it has 2 Special Chars from the List preg_match("/(.*[!,@,#,$,%,^,&,*,?,-,_,~].*[!,@,#,$,%,^,&,*,?,-,_,~])/", $pass); // Check if Email is in Valid Format preg_match("/^(?i)[0-9a-z]([-.\\w]*[0-9a-z])*@([0-9a-z][-\\w]*[0-9a-z]\\.)+[a-z]{2,9}\$/", $email); //Check to make sure First Name has only letters, hyphens, or an apostrophes! preg_match("/^(?i)[-a-z']$/", $fname); // Check to make sure Last Name has only letters, hyphens, or apostrophes! preg_match("/^(?i)[-a-z']$/", $lname); ?> Now each and every single one of these features works properly in Javascript, unfortunately I can't quite figure out how to get them to work properly in PHP. I use ( ! ) to check if there isn't a match, but the RegExp is giving me a bit of a headache. What should be valid comes back as invalid. I can't remember which I actually did, and which I just copied or found somewhere else. I just want the torture to stop! Can anyone help? I saw an example when i was learning pcre recently. It is in dot chapter and its address is at http://php.net/manua...ference.dot.php. The codes like this:
Consider, preg_match_all("/<img.*>/", $htmlfile, $match); preg_match_all("/(*ANY)<img.*>/", $htmlfile, $match); Now, any character that could possibly be seen as a newline will be interpreted as a newline by the PCRE.My question is "Does the dot character in pattern preg_match_all("/(*ANY)<img.*>/", $htmlfile, $match) really match newline?" I have thought quite some time but still don't know why. Can anyone help solve this question for me? Thanks! This is the first time Im trying to use REGEXP, but cant get it working. It gives no error, just nothing..Anyone got idea why, please? Thanks <?php include ('connectToDatabase.php'); $getSearch = $_REQUEST['getSearch']; $keywordSearchQuery = "SELECT shoeName, shoeSize, colour, price, gender, description WHERE shoeName REGEXP '.*($getSearch).*' || shoeSize REGEXP '.*($getSearch).*' || colour REGEXP '.*($getSearch).*' || price REGEXP '.*($getSearch).*' || gender REGEXP '.*($getSearch).*' || description REGEXP '.*($getSearch).*" ; $keywordSearchQueryResult = mysql_query($keywordSearchQuery); echo "$keywordSearchQueryResult"; ?> hi guys, i am trying to create a button that when u press if in the text are will appear <video>...</video> i know this is js do don't worry i will manage to do it, my problem is in php, i did a function that recognizes the link between <video>...</video> and then it embades it and shows me a youtube video instead, the problem i got is that if i have in the text area more <video>...</video>, like: bla bla bal<video>youtube link</video> and the other vid <video>youtube link</video> i dont know how to make it embade both, i dont know how to check if there is more, and the second problem i got is that all the text that was not betwen <video>...</video> will disapear after the vide is embadded, here is the code i done until now Code: [Select] <form action="test1.php" method = "POST"> <textarea name="body" id="text" cols="30" rows="10"></textarea> <input type="submit" value = "submit"> </form> <?php function video($string){ preg_match_all("#<video\b[^>]*>(.*?)</video>#", $string, $output); preg_match_all("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $output[0][0], $match); return "<iframe width='560' height='315' src='http://www.youtube.com/embed/".$match[0][0]."' frameborder='0' allowfullscreen></iframe>"; } if (isset($_POST['body'])&&!empty($_POST['body'])) { $body = $_POST['body']; print_r(video("$body")); } ?> Hi there, im looking for a little bit of help, could someone who knows how to use REXEXP properly tell me how i would select only the uppercase titles from title column and display them Code: [Select] +------------+-----------+ | id | title | +------------+-----------+ | 1 | one | | 2 | TWO | | 3 | three | | 4 | FOUR | +------------+-----------+ Code: [Select] <?php $username="user"; $password="pw"; $database="db"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT title FROM template WHERE name REGEXP '^(A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z)'"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Custom Template Name : {$row['title']} <br><br>"; } mysql_close(); ?> This was an attempt i made but it did not work i got the following error: Quote Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\ProgramData\xampp\htdocs\test.php on line 14 I did attempt to do a search on it but if im honest i didnt fully understand what they were saying. Im using php 5.3.5 and mysql 5.5.8 Thanks for your help Folks, I am just trying to learn PHP. For form input validation which is better - Regexp or PHP Filters? Or do they have completely different uses? Where does preg fit in? Thank you! J.S. Hi Guys I am having trouble with a mysql regexp expression called through php. I am not sure but I suspect its to do with the {} in the mysql code and PHP parsing them incorrectly. Here is my code snippet: $q = mysql_real_escape_string($_POST['keyword']); $limit = 10; //limit number of responses from dictionary $remainder = 11 - strlen($q); if ($q) { $qy = "SELECT * FROM dict_list WHERE UCASE(word) <> UCASE('$q') AND (word REGEXP '^$q.{$remainder}') LIMIT $limit"; $query = mysql_query($qy); ... What I want to do is this: a user types in a word. I then want to query a dictionary table called dict_list for all matches of the this word up to 11 characters max. Example: if $q was the word aero then the response would be all words beginning with aero and up to a max of 11 characters. That is why IU thought I could calculate length of $q and from this get the $remainder = 11 - strlen($q) then in the REGEXP use .{$remainder} but when testing if I echo out the query $qy the curly braces will not show on screen. Any help would be greatly appreciated. I hope this is posted in correct location. Apologies if not. Thanks, Fergal. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=318277.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=342987.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=313579.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=318465.0 This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=331097.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=343318.0 The PHP Coding Help section is not the place to recruit someone to work on your project. It's for answering specific questions about specific code. This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=347446.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=327250.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=356760.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328753.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309960.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=319767.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=346829.0 |