JChilds Posted June 1, 2008 Share Posted June 1, 2008 I'm trying to use preg_match to retun all numbers that are between ID= and " ie; ID_1234567" will retun 1234567 This is what i have used: preg_match('^id_[-+]?\d+"$', 'input', $matches); But I keep getting the error Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /home/noexcuse/public_html/id.php on line 8 Can anyone please help me? This is driving me mad! Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 1, 2008 Share Posted June 1, 2008 Use: preg_match('/^id_[\d]+$/', 'input', $matches); Quote Link to comment Share on other sites More sharing options...
JChilds Posted June 1, 2008 Author Share Posted June 1, 2008 Use: preg_match('/^id_[\d]+$/', 'input', $matches); Thanks for the speedy reply. When I use preg_match('/^id_[\d]+$/', 'input', $matches); With an input of id_1234567 I just get an output of "Array" :S Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 1, 2008 Share Posted June 1, 2008 preg_match returns an array of matches. use: preg_match('/^id_[\d]+$/', 'input', $matches); echo '<pre>' . print_r($matches, true) . '</pre>'; To see the matches returned from the expression. Quote Link to comment Share on other sites More sharing options...
JChilds Posted June 1, 2008 Author Share Posted June 1, 2008 preg_match returns an array of matches. use: preg_match('/^id_[\d]+$/', 'input', $matches); echo '<pre>' . print_r($matches, true) . '</pre>'; To see the matches returned from the expression. Thanks. I'm still learning. Now, with an input of id_1234567" I get an output of Array ( ) Here is exactly what I have <?php $input = $_POST["input"]; preg_match('/^id_[\d]+$/', 'input', $matches); echo '<pre>' . print_r($matches, true) . '</pre>'; ?> I am probably just making some stupid beginner mistake Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 1, 2008 Share Posted June 1, 2008 Are you wanting to match the quote after the numbers too: id_1234567" Also 'input' should be $input <?php $input = $_POST["input"]; preg_match('/^id_[\d]+"$/', $input, $matches); echo '<pre>' . print_r($matches, true) . '</pre>'; ?> Quote Link to comment Share on other sites More sharing options...
JChilds Posted June 1, 2008 Author Share Posted June 1, 2008 Are you wanting to match the quote after the numbers too: id_1234567" Also 'input' should be $input <?php $input = $_POST["input"]; preg_match('/^id_[\d]+"$/', $input, $matches); echo '<pre>' . print_r($matches, true) . '</pre>'; ?> Thankyou. Yes, the quote aswell. There are about 200 lines of input similar to this (source of a page) <td><input name="id_1523023" type="checkbox" /> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 1, 2008 Share Posted June 1, 2008 Could you explain what you are trying to achieve? What is in $_POST['input'] ? Quote Link to comment Share on other sites More sharing options...
JChilds Posted June 1, 2008 Author Share Posted June 1, 2008 Ok. Ill start right from the start. I want to be able to paste the source code from a certain webpage into a form. eg <td><input name="id_1523023" type="checkbox" /> (about 200 lines though, all with different Id's) I want it to tell me all the ID's in a simple list without the 'id_' or ' " ' Also (just to make things difficult) I'd love it to start from teh bottom of the page. Or re-arange the ID's the opposite way they were found. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 1, 2008 Share Posted June 1, 2008 Better of using preg_match_all $input = $_POST['input']; preg_match_all('/name="id_([\d]+)"/', $input, $matches); echo '<pre>' . print_r($matches[1], true) . '</pre>'; Quote Link to comment Share on other sites More sharing options...
JChilds Posted June 1, 2008 Author Share Posted June 1, 2008 Better of using preg_match_all $input = $_POST['input']; preg_match_all('/name="id_([\d]+)"/', $input, $matches); echo '<pre>' . print_r($matches[1], true) . '</pre>'; That returns an empty array again Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 1, 2008 Share Posted June 1, 2008 Is your textarea that you post the HTML code in called input? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.