GD77 Posted September 29, 2012 Share Posted September 29, 2012 Helllo: Need to add the html tag <li>...</li> to this plz: preg_match('/^[a-z0-9_\/a\-\ ]+$/si',$va1) Thanks. Quote Link to comment Share on other sites More sharing options...
GD77 Posted September 29, 2012 Author Share Posted September 29, 2012 ok I m using the following and it s working: preg_match('/^[a-z0-9_\/a\-\<li\>(.*?)<\/li\>\ ]+$/i',$va1) need to escape new line character cause m using a wysiwyg editor on a textarea apparently when i m submiting with new line it returns False... Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 29, 2012 Share Posted September 29, 2012 Just add it in your pattern [^\n] or if you have more than one [^\n]+ Quote Link to comment Share on other sites More sharing options...
GD77 Posted September 29, 2012 Author Share Posted September 29, 2012 no not working Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 29, 2012 Share Posted September 29, 2012 Could you show us the text that you'd like to validate, also your RegEx string, and finally var_dump($va1). Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 29, 2012 Share Posted September 29, 2012 Try, preg_match('/^[a-z0-9_\/a\-\<li\>(.*?)<\/li\>\ ]+[^\n]?$/i',$va1) Quote Link to comment Share on other sites More sharing options...
GD77 Posted September 29, 2012 Author Share Posted September 29, 2012 $va1 receiving the data from a textarea the codes till I use new line btw why used ? instead of + in: +[^\n]?$/i main code: if(!preg_match('/^[a-z0-9_\/a\-\<li\>(.*?)<\/li\>\ ]+[^\n\r]+$/i',$va1)){.....} Quote Link to comment Share on other sites More sharing options...
Christian F. Posted September 29, 2012 Share Posted September 29, 2012 (edited) Jazzman: [^\n] matches everything that's not a newline character, exactly the opposite of what GD77 wanted. GD77: Remove the caret from the newline character group, and it should match as you want it to. Here's it a bit cleaned up, and properly escaped for PHP strings too: '#^[a-z0-9_/a+ -]+<li>(.*?)</li>[\\n\\r]+\\z#i' Doing this cleanup I found another problem too, namely the fact that you've added the LI tag patter inside the character group. Which caused it to consider the individual characters as part of a group, not as a pattern you wanted matched. I've moved it outside for you, but without any example data I cannot know if this pattern matches what you want. BTW: What's the escaped space after the closing LI-tag? Edited September 29, 2012 by Christian F. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 29, 2012 Share Posted September 29, 2012 (edited) Ah, my apology. You want to match new lines $pattern = '/^[\n\r]?[a-z0-9_\/a\-\<li\>(.*?)<\/li\>\ ]+/i'; if(preg_match($pattern, $va1)){ echo 'true'; } else { echo 'false'; } @Christian, you pattern won't work, why are you using [\\n\\r] ? Edited September 29, 2012 by jazzman1 Quote Link to comment Share on other sites More sharing options...
GD77 Posted October 1, 2012 Author Share Posted October 1, 2012 thx jazzman1 ya it s working. Quote Link to comment Share on other sites More sharing options...
GD77 Posted October 1, 2012 Author Share Posted October 1, 2012 jazzman1 the code is match < test it their http://erik.eae.net/playground/regexp/regexp.html even in my php page... if you type <script> or <bi> instead of <li> it returns true Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 1, 2012 Share Posted October 1, 2012 Unfortunately, the code posted by Jazzman only seems to be working. It has the same issues that I highlighted for your code, due to the grouping of the li-tags inside the square brackets. For all intents and purposes, this is exactly the same: '#^[\\n\\r]?[\\w?./<>() *-]+#i' Note that neither period, asterisk, question marks or parenthesis has any special meaning within a character group. Now, if you want help to making something that actually matches what you want it to match, you need to post an example of the source data. As I requested above. Quote Link to comment Share on other sites More sharing options...
GD77 Posted October 2, 2012 Author Share Posted October 2, 2012 what it should match is any text including new line and li tags simple ex: text tetx 1252 ext text2 text 2 <li>text2</li> text 3... Quote Link to comment Share on other sites More sharing options...
GD77 Posted October 2, 2012 Author Share Posted October 2, 2012 only need the <li> might use [li] and i ll substitute i later does not matter just don t want to allow <> for </script> or nothing else to be used Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted October 2, 2012 Share Posted October 2, 2012 If your problem is <some text></some text> tags, just find and replace them in the string with <li> or [li].... Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 2, 2012 Share Posted October 2, 2012 (edited) In that case I recommend using something like this: $RegExp = '#((?:[\\w\\r\\n/ -]|<li>.*?</li>)+)#is'; This will grab the entire text in your example, and only if you have a balanced pair of li-tags (or none at all). Edited October 2, 2012 by Christian F. Quote Link to comment Share on other sites More sharing options...
GD77 Posted October 2, 2012 Author Share Posted October 2, 2012 Christian F. thx a lot mate worked fine Quote Link to comment Share on other sites More sharing options...
GD77 Posted October 2, 2012 Author Share Posted October 2, 2012 jazzman1 thx too Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.