RE: Php question from Newsgroup

From: Date: Thu, 18 Dec 2008 16:04:10 +0000
Subject: RE: Php question from Newsgroup
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-284792@lists.php.net to get a copy of this message
Mike -- I've "bottom posted" my reply, as is the convention for this list (and most others). Scroll down. ---- From: Mike Peloso [mailto:mpeloso@Princeton.EDU] Sent: Thursday, December 18, 2008 9:56 AM To: Boyd, Todd M. Subject: Php question from Newsgroup Todd, I have attached a few jpgs to show the problems I am having (With both of my recent posts) Any questions you can call me. The first one shows the value of the php file I am trying to parse.( I cant set any of those directives,) I can't set php.ini per dir The second shows what your REGEX looks like as its being sent to: preg_match_all($regex, $test2, $result, PREG_PATTERN_ORDER); As you can see there is a whole lot of escaping going on here. Thanks Mike Heres all the code: <?php process_uploaded_file('letter'); function process_uploaded_file($fname) {     // Assumes set of $_POST variables in the form: name, name_fname, name_size, name_type     $_POST[$fname.'_fname'] = $_FILES[$fname]['name'];     $_POST[$fname.'_size'] = $_FILES[$fname]['size'];     $_POST[$fname.'_type'] = $_FILES[$fname]['type'];     $_POST[$fname.'_fname'] = strtr($_POST[$fname.'_fname'],' %&*;:"{}[]|\<>,/()%$#@!','________________________'); //fix special chars in name     $_POST[$fname.'_fname'] = strtr($_POST[$fname.'_fname'],"'","_");     $fileHandle = fopen($_FILES[$fname]['tmp_name'], "r");     $_POST[$fname] =stripslashes(fread($fileHandle, $_POST[$fname.'_size']));     $test=$_POST[$fname];     $test3=stripslashes($test);     //$regex='/function [a-z]* *([$a-zA-Z]*)/';     //$regex='/function [a-z]* *(?$[a-z]*)?/';     $regex = '/function\s+[-_a-z0-9]+\s*\((\s*$\?[-_a-z0-9]+\s*,?)*\s*\)/i';     $functions=do_reg($regex,$test); }   function do_reg($regex,$test) {   $test2=preg_quote($test);     preg_match_all($regex, $test2, $result, PREG_PATTERN_ORDER);     return $result = $result[0]; } ?> ---- Mike, You are using preg_quote(). This will add slashes to every "special" RegEx character in your pattern (i.e., parentheses and dollar signs, etc.). Try performing your RegEx search without using preg_quote() and let me know if it does any better. Also--try to keep your replies on the PHP List, as the information in them can be used by others on their own projects. // Todd

« previous php.general (#284792) next »