Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

option value

Posted on 2013-05-12
6
Medium Priority
?
342 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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

618 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