Solved

option value

Posted on 2013-05-12
6
334 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
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 108

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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.
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 …

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now