Solved

option value

Posted on 2013-05-12
6
339 Views
Last Modified: 2013-05-13
<option value="want this value">words</option>
how to get the value out of the option
0
Comment
Question by:rgb192
[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
6 Comments
 
LVL 21

Expert Comment

by:Mazdajai
ID: 39160187
(?:<option value="(.*?)">)

Open in new window

0
 

Author Comment

by:rgb192
ID: 39160191
Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 0
$text='<option value="">words</option>';
$pattern = '(?:<option value="(.*?)">)';
preg_match($pattern, $text, $option_matches);
print_r($option_matches);
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39160202
Not so clear your question ??
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 250 total points
ID: 39160207
$text='<option value="want this">words</option>';
$pattern = '#<option value="([^"]*)">#i';
preg_match($pattern, $text, $option_matches);
print($option_matches[1]);

Open in new window

0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39161314
The question mark is a meta-character in regular expressions.  I would instinctively avoid using a meta-character as a delimiter.  And while you can often parse HTML documents with regular expressions, there is nothing guaranteed here, especially if you did not write the HTML.  Invalid HTML can still be rendered by a browser and many developers do not understand or use HTML validation, so your script is always at risk of running into something that will not parse correctly.  

<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('log_errors',     TRUE);

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28125819.html
$str = <<<EOD
<option value="want this value">words</option>
EOD;

// FIND THE CHARACTER STRING IN THE 'VALUE' ATTRIBUTE
$obj = SimpleXML_Load_String($str);
$sub = (string)$obj->attributes()->value;

// SHOW THE WORK PRODUCT
var_dump($sub);

Open in new window

Best regards, ~Ray
0
 

Author Closing Comment

by:rgb192
ID: 39162174
these work in finding value

thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
$_SERVER Variable question 31 56
Survey branching tutorial 11 44
Delete image(s) associated with record(s) 16 29
if statement malfunction 5 24
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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