typeslowly Posted December 22, 2007 Share Posted December 22, 2007 $url = "http://www.example.com/1; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $page = curl_exec($ch); curl_close($ch); $regex = '/[v][0-9]{5}[A-Za-z0-9]{8}/'; preg_match($regex,$page,$match); var_dump($match); echo $match[1]; Hi, I'm trying to make this code repeat with the number at the end of the URL changing every time. How do I set a a range of numbers? What would be the best way to store all this data? Sorry if this a dumb question, I tried searching and got nothing. Link to comment https://forums.phpfreaks.com/topic/82801-how-to-repeat-something-with-small-variation/ Share on other sites More sharing options...
Barand Posted December 22, 2007 Share Posted December 22, 2007 try <?php $numbers = range (1, 50); foreach ($numbers as $n) { $url = "http://www.example.com/$n"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $page = curl_exec($ch); curl_close($ch); $regex = '/[v][0-9]{5}[A-Za-z0-9]{8}/'; preg_match($regex,$page,$match); var_dump($match); echo $match[1]; } ?> Link to comment https://forums.phpfreaks.com/topic/82801-how-to-repeat-something-with-small-variation/#findComment-421102 Share on other sites More sharing options...
typeslowly Posted December 22, 2007 Author Share Posted December 22, 2007 That works great, thanks. But it comes out really weird(to me) array(1) { [0]=> string(14) "v554652GWNXwwR" } Arrayarray(1) { [0]=> string(14) "v554657ky4CDT8" } Arrayarray(1) { [0]=> string(14) "v554654a826KZG" } Arrayarray(1) { [0]=> string(14) "v554653QzA7C5p" } Arrayarray(1) { [0]=> string(14) "v5546566Jr9zsY " } Arrayarray(1) { [0]=> string(14) "v554655JnBWd4x " } Arrayarray(1) { [0]=> string(14) "v554658Ybj4xKY" } Arrayarray(1) { [0]=> string(14) "v55465992CnjqC" } Arrayarray(1) { [0]=> string(14) "v554660NAX6bDR" } Arrayarray(1) { [0]=> string(14) "v554661sA79eqp" } Arrayarray(1) { [0]=> string(14) "v554662MF8Gyy6 " } Arrayarray(1) { [0]=> string(14) "v554663FpMNGHc " } Arrayarray(1) { [0]=> string(14) "v10514612RdCCk " } Arrayarray(1) { [0]=> string(14) "v554670N34jke7 " } Arrayarray(1) { [0]=> string(14) "v5546718DyMZpw " } Arrayarray(1) { [0]=> string(14) "v5546723QPaM4N" } Arrayarray(1) { [0]=> string(14) "v554673JhwskMJ" } Arrayarray(1) { [0]=> string(14) "v962240SBK3REq" } Arrayarray(1) { [0]=> string(14) "v554666QWtbAAZ" } Arrayarray(1) { [0]=> string(14) "v554668dByX7Hx" } Arrayarray(1) { [0]=> string(14) "v554664BaSCKEE" } Arrayarray(1) { [0]=> string(14) "v554676m4EQxze" } Arrayarray(1) { [0]=> string(14) "v554667mKppgRN" } Arrayarray(1) { [0]=> string(14) "v554674rEXyj87" } Array How can I get all of those into a .csv file or something so I can manipulate them easier? I don't even know how to ask the question, haha. If you could give some general topics I could read about this, that would be cool. How do you make your code colored> Link to comment https://forums.phpfreaks.com/topic/82801-how-to-repeat-something-with-small-variation/#findComment-421103 Share on other sites More sharing options...
Barand Posted December 22, 2007 Share Posted December 22, 2007 var_dump() can be bit cluttered. Clearer if you put the output between "pre" tags echo '<pre>', print_r($match, true), '</pre>'; To get php code color-coded, put "<?php" at the start of the code <?php echo '<pre>', print_r($match, true), '</pre>'; See www.php.net/fputcsv Link to comment https://forums.phpfreaks.com/topic/82801-how-to-repeat-something-with-small-variation/#findComment-421106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.