?
Solved

RELATED:  How do I structure this drop down correctly w/regex?

Posted on 2011-09-13
7
Medium Priority
?
293 Views
Last Modified: 2012-05-12
Kaufmed & Experts,

I have attempted to structure this statement, however I am having an issue with the lookahead.  How do I fix this?

Thanks for your help!!



Original source:

<select name="SKU_0" size="1" onchange="javascript:ChangeItemId(document.form1.varitemid_0,document.form1.SKU_0);">
 
                                                                    <option value="BSC11" selected>Black
                                                                    <option value="BSC12" >Blue
                                                                    <option value="BSC13" >Red
                                                                    <option value="BSC14" >Green
                                                                    <option value="BSC15 >Yellow
                                                                    <option value="BSC16" >Gray
                                                                </select>







preg_match_all('%<option value="(.*?)" ?=(selected)>([a-zA-Z]{10})%',$buffer,$matches39,PREG_SET_ORDER);
								

foreach ($matches39 as $val39) {

$option1=$val39[1];
$option2=$val39[2];
$option3=$val39[3];
$option4=$val39[4];
$option5=$val39[5];
$option6=$val39[6];
$option7=$val39[7];
$option8=$val39[8];

Open in new window

0
Comment
Question by:rlb1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36531981
Can you clarify what it is you are trying to capture?
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 total points
ID: 36532766
I'm guessing you want something like this, which captures the value and the option description:
preg_match_all('#<option value="([^"]*)"\s*(?:selected)?>([a-zA-Z]{1,10})#',$sourcestring,$matches);

Output:
    [0] => Array
        (
            [0] => <option value="BSC11" selected>Black
            [1] => <option value="BSC12" >Blue
            [2] => <option value="BSC13" >Red
            [3] => <option value="BSC14" >Green
            [4] => <option value="BSC16" >Gray
        )

    [1] => Array
        (
            [0] => BSC11
            [1] => BSC12
            [2] => BSC13
            [3] => BSC14
            [4] => BSC16
        )

    [2] => Array
        (
            [0] => Black
            [1] => Blue
            [2] => Red
            [3] => Green
            [4] => Gray
        )
0
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 2000 total points
ID: 36532772
I'd also recommend adding the i pattern modifier to ignore case, and make it more robust:

preg_match_all('#<option value="([^"]*)"\s*(?:selected)?>([a-zA-Z]{1,10})#i',$sourcestring,$matches);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Closing Comment

by:rlb1
ID: 36533378
Thank you for your help Terry & Kaufmed!
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36533519
I can't in good conscience accept points for my comment...  Terry's really the one who got you sorted out, though I appreciate the gesture  = )
0
 

Author Comment

by:rlb1
ID: 36533537
Kaufmed,  you and Terry have been exceptionally good to me on EE!  Thanks for helping me learn this stuff!!
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question