?
Solved

option value

Posted on 2013-05-12
6
Medium Priority
?
341 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
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!

 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 1000 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 111

Accepted Solution

by:
Ray Paseur earned 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses

770 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