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
Solved

option value

Posted on 2013-05-12
6
338 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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 109

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
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 count occurrences of each item in an array.

828 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