Jump to content

Regular Expression Question


kevinkhan

Recommended Posts

<input type=\"hidden\" autocomplete=\"off\" name=\"xhpc_composerid\" value=\"u269995_3\" \/>

 

im trying to extract the value of the xhpc_composerid..

 

How do i go about doing it and what is wrong with this code

 

preg_match('|<input[a-zA-Z =\\\"_]*name=\\\"xhpc_composerid\\\"[ ]*value=\\\"[0-9a-zA-Z]*\\\"[a-zA-Z =\\\"]*/>|', $page, $match);

 

can anybody give me the correct solution and explain how it works

 

Thanks

Link to comment
Share on other sites

You aren't accounting for the _ in the value.

 

Since you wrote 0-9a-zA-Z and you also need to account for _ you'd be better off writing \w instead.

 

so can somebody write the full correct regex that i can use please..

 

sorry this is the next topic i have to learn...

Link to comment
Share on other sites

<?php
$page ="<input type=\"hidden\" autocomplete=\"off\" name=\"xhpc_composerid\" value=\"u269995_3\" \/>";
preg_match('|<input\s[^>]*name="xhpc_composerid"\s[^>]*value="([^"]*)"[^>]*>|', $page, $match);
print_r($match);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.