preg-match

Beginner PHP help needed

跟風遠走 提交于 2019-12-11 02:10:28
问题 I have been learning PHP for some time now and I wanted one clarification. I have seen the preg_match function called with different delimiting symbols like: preg_match('/.../') and preg_match('#...#') Today I also saw % being used. My question is two part: What all characters can be used? And is there a standard ? 回答1: Any non-alphanumeric non-whitespace and non-backslash ASCII character can be used as delimiter. Also if you using the opening punctuation symbols as opening delimiter: ( { [ <

preg_match easiest way to match text from inside html tags [duplicate]

你。 提交于 2019-12-11 01:45:46
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Best methods to parse HTML with PHP for example i have a html code like : <table width="100%" border="0" cellspacing="0" cellpadding="0" class="rowData"> <tr align="center" class="fnt-vrdana-mavi" > <td style="font-size:11px" colspan=3><b>Text text text</b>:3</td> </tr> <tr class="header" align="center"> <td height="18" colspan="3">Text text text</td> </tr> <tr align="center" class="fnt-vrdana" bgcolor="#eff3f4"

php regex named groups

六眼飞鱼酱① 提交于 2019-12-11 01:35:31
问题 can someone tell me how to use named groups syntax in PHP? I'm trying to parse a simple math equation, for example someVariable!=someValue . I'd like to get 3 values from matching operation, stored in 3 variable variable , operator , value . 回答1: Is this basically what you're looking for? $equation = 'someVariable!=someValue'; $matches = array(); preg_match('~^(\w+)([!=]+)(\w+)$~', $equation, $matches); $variable = $matches[1]; $operator = $matches[2]; $value = $matches[3]; The actual regular

preg_match rule for utf-8

南笙酒味 提交于 2019-12-10 23:49:49
问题 what pregmach rule i must use for full_name field? i want user input only character and not html or php code value and space between 3 to 11 character i can use: <?php if (preg_match("%^[A-Za-z0-9-_]{3,10}$%", $_REQUEST['usr'])) { //do something like mysql_query('insert into user(name) values(this field)'); //damn what is this for: It does not meet our quality standards.!!! //i must insert more code? i dont have ! let me go ! } else{ //do something else! die('get out !:D'); } ?> but with this

Why is this regex failing when adding anchors?

左心房为你撑大大i 提交于 2019-12-10 23:38:03
问题 This is a match: preg_match('/[a-bA-B0-9]+/', 'username') But this is not: preg_match('/^[a-bA-B0-9]+$/', 'username') Why is that? 回答1: Are you testing the actual literal 'username' ? /[a-bA-B0-9]+/ will test the existence of a,b,A,B,0,1,2,3,4,5,6,7,8,9 anywhere in the string. So it will match abBa854Abba32 , and it will match sjfsgfafnvesv . /^[a-bA-B0-9]+$/ will test that the enitre string is made of a,b,A,B,0,1,2,3,4,5,6,7,8,9. So it will match abBa854Abba32 , and it will not match

Conditional regex in PHP doesn't seem to work

社会主义新天地 提交于 2019-12-10 23:31:53
问题 Performing a regular expression match in PHP using the preg suite, I understand that you can represent a conditional statement right within the regex. I could hardly find any documentation online so I turned to Jeffrey E.F. Friedl's Mastering Regular Expressions. The way I see it, something like /(?(?<=NUM:)\d+|\w+)/ should match a digit when it is preceded by NUM: otherwise it should match a word. But for some weird reason it always returns true and the match data doesn't make sense to me

preg_match exact number

寵の児 提交于 2019-12-10 20:43:27
问题 I'm using $regex = '/'.implode('|', 10).'/i'; preg_match($regex, $ids) to find the number 10 in a list of IDs ($ids). However, if the list of IDs looks like this: $ids = array(10, 110, 1010); Would it bring back all of them? How can I make it find the exact number I am after, and not just find a number that contains the number I'm after? Thanks. Edit: I made a mistake above. The list of IDs is actually a string of comma separated values. For example: $ids = "10,1010,101"; It's hard to explain

Getting contents of square brackets, avoiding nested brackets

℡╲_俬逩灬. 提交于 2019-12-10 18:44:59
问题 (first time poster, long time visitor via Google) I'm trying to extract the contents of some square brackets, however i'm having a spot of bother. I've got it working for round brackets as seen below, but I can't see how it should be modified to work for square brackets. I would have thought replacing the round for square and vice versa in this example should work, but apparently not. It needs to ignore brackets within brackets. So it won't return (11) but will return (10(11)12). $preg = '#\(

Php Regex to find if string is mysql select statement

▼魔方 西西 提交于 2019-12-10 18:35:54
问题 I'm trying to validate queries before executing them, If query is not a mysql select statement then i have to show message to user. I found below regex from this link: Validate simple select query using Regular expression $reg="/^Select\s+(?:\w+\s*(?:(?=from\b)|,\s*))+from\s+\w+\s+where\s+\w+\s*=\s*'[^']*'$/i"; next i wrote below code but it always prints not select query ($match is empty every time) $string="select * from users where id=1"; preg_match_all($reg,$string,$match); if(!empty(

PHP preg_match specific field value

女生的网名这么多〃 提交于 2019-12-10 17:28:29
问题 I want to get the id or the name of a field that keeps changing its value. Example: I have these fields in my form: <input type="text" id="94245" name="94245" value=""> <input type="text" id="name" name="name" value=""> <input type="text" id="status" name="status" value=""> And I want to get the ID or the name of the first field, but it keeps changing, like: <input type="text" id="52644" name="52644" value=""> <input type="text" id="44231" name="44231" value=""> <input type="text" id="94831"