JChilds Posted June 2, 2008 Share Posted June 2, 2008 Thanks to Crayon Violent I have a shiny new script. <?php $input = $_POST["input"]; $notebook = "James XXXXXXX test"; preg_match_all("/id_[1-9]?\d+/",$input,$info); $info = array_reverse($info[0]); $x = 0; while ($info[$x]) { $info[$x] = ltrim($info[$x],'id_'); $x++; } foreach($info as $i) { echo $i. "<br />"; } ?> I am just wondering where in here I would put 'str_replace('XXXXXXX',$info,$notebook);' I assume this will replace the XXXXXX with the first line of $info Quote Link to comment https://forums.phpfreaks.com/topic/108317-solved-str_replace/ Share on other sites More sharing options...
rajug Posted June 2, 2008 Share Posted June 2, 2008 Though i am not clear about your problem but the line you are supposing put would work except $info is an array so instead of array you just need to put a single element of that array. AFAIK the replacing value $info should be a string. Quote Link to comment https://forums.phpfreaks.com/topic/108317-solved-str_replace/#findComment-555325 Share on other sites More sharing options...
JChilds Posted June 2, 2008 Author Share Posted June 2, 2008 Though i am not clear about your problem but the line you are supposing put would work except $info is an array so instead of array you just need to put a single element of that array. AFAIK the replacing value $info should be a string. Sorry, I should have made myself more clear. I have an array ($array) I have a text file ($notebook) $notebook contains "James XXXXXXX test" $array contains a 7 digit number (eg 1234567) I want to replace the X's with the numbers. Quote Link to comment https://forums.phpfreaks.com/topic/108317-solved-str_replace/#findComment-555328 Share on other sites More sharing options...
JChilds Posted June 2, 2008 Author Share Posted June 2, 2008 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/108317-solved-str_replace/#findComment-555349 Share on other sites More sharing options...
rajug Posted June 2, 2008 Share Posted June 2, 2008 Umm I don't know you are trying to achieve this: $notebook = 'James XXXXXXX test'; $replace = '1234567'; $find = 'XXXXXXX'; echo str_replace($find, $replace, $notebook); Quote Link to comment https://forums.phpfreaks.com/topic/108317-solved-str_replace/#findComment-555355 Share on other sites More sharing options...
JChilds Posted June 2, 2008 Author Share Posted June 2, 2008 Umm I don't know you are trying to achieve this: $notebook = 'James XXXXXXX test'; $replace = '1234567'; $find = 'XXXXXXX'; echo str_replace($find, $replace, $notebook); All I get as output is 'Array' when ; $notebok = ' test1 XXXXXXX test2 XXXXXXX '; $replace = $array; $find = 'XXXXXXX'; echo str_replace($find, $replace, $notebook); Quote Link to comment https://forums.phpfreaks.com/topic/108317-solved-str_replace/#findComment-555373 Share on other sites More sharing options...
rajug Posted June 2, 2008 Share Posted June 2, 2008 Can you please say here that what exactly the variable $array holding so that it could make more closer to say the solution? I don't think that the problem is too much complicated. Quote Link to comment https://forums.phpfreaks.com/topic/108317-solved-str_replace/#findComment-555381 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.