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! Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/ Share on other sites More sharing options...
wildteen88 Posted June 1, 2008 Share Posted June 1, 2008 Use: preg_match('/^id_[\d]+$/', 'input', $matches); Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554822 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 Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554824 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. Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554828 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 Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554832 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554837 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" /> Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554839 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'] ? Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554842 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. Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554847 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>'; Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554854 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 Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554860 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? Link to comment https://forums.phpfreaks.com/topic/108241-no-ending-delimiter-found-in-what-have-i-done/#findComment-554897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.