Link to home
Start Free TrialLog in
Avatar of Ralph
RalphFlag for United States of America

asked on

PHP preg_match problem with print-ables between necessary quotes

I'm writing some html form reading routines and my knowledge of REs has apparently run out.

I can't find the codes to use for matching names/values/whatever when they include periods betw quotes.
e.g.: ....  name="customer.cust_name" ...

I'm aware of [:print:] but that won't work between quotes, at least the way I'm trying it.

I'm using:
        $pattern = '/'.$part.'\="\w*"/' ;
        preg_match($pattern,$spaceless, $matches) ;
        return substr($matches[0], strlen($part)+2, -1) ;    // this is line 206

Open in new window

Where $part is sometimes "value" or "name".

Sample output below.  My tracing echos give me row# and cols for field borders, etc.
(I'm not going to worry about %xx; chars between quotes at this time.)

row=137
48 123             <span class="field_left"> Customer: <input type="text" name="customer.cust_name" value="Fred Flinstone" size="30"  disabled /></span>
matched_with = <input

Notice:  Undefined offset: 0 in C:\XAMPP\htdocs\Cell_Modems\PHP\parse_form.php on line 206

name= 
type=text
value=Fred Flinstone

Open in new window


Clarifying my question:  What pattern should I use for preg_match?

Thanks!
Avatar of Uros Gaber
Uros Gaber

A simple regex that will match anything that has a period between quotes would be:
(\".*\..*\") - this will match ".", "a.", ".b"
(\".+\..+\") - this will match "a.b"

Open in new window

inside a string

hope this helps
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ralph

ASKER

Prompt and excellent feedback by both of you.  Thanks!

Why am I doing this?
I will be pulling a lot of data, particularly 'choose from' data from MySQL and I want to populate HTML forms without the usual 'this part' from here and 'this part' from here and ...  So I've made my HTML 'templates' and I'm using PHP, not the best choice but it's what I get to use, to parse the template ahead of time and build a matrix (crazy nesting of arrays) to store what is where, so that when the data flows in it'll be a few function calls to tweak the source to make fully functioning forms.  (A side benefit will be neatness of the finished HTML and ease of use in assembling the page that goes online.)

I'm never sure unless I try and/or look up whether a RE is 'greedy' or 'lazy'.  For instance in this case, when I might grab/include quotes and walk away with the whole line.

Thanks for the clean layout too, certainly educational!

Ralph
Glad it was helpful.  Thanks for the points and thanks for using E-E! ~Ray