jamesxg1 Posted February 12, 2010 Share Posted February 12, 2010 Hiya peeps! I cant figure this out for love nore money! LOL! I was wondering how I would split and array up into peices or strings without foreach() . Many thanks James. Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 12, 2010 Share Posted February 12, 2010 implode() Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted February 12, 2010 Author Share Posted February 12, 2010 implode() Thanks for the reply mate! Only problem im having is my array goes a little something like this. array('HOME' => 'home', 'TITLE' => 'title'); Heres what I have foreach($parts as $part => $value): echo str_replace('{' . $part . '}', $value, $file) . '<br /><br />'; endforeach; But if there is 2 items in an array the loop is ran twice :S. Many thanks James. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 12, 2010 Share Posted February 12, 2010 Isn't that what a loop i supposed to do? Why are you thinking that foreach would be a bad solution? However, based upon the code posted I am assuming you are wanting to do multiple string replacements. If so, then you can use arrays as the search and replacement values. The problem you have with the current setup is that your actual search values are enclosed in brackets. So, you would have to modify the values of your search values. $search = array_keys($parts); foreach($search as $key=>$value) { $search[$key] = "{".$value."}"; } echo str_replace($search, $parts, $file) . '<br /><br />'; Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted February 12, 2010 Author Share Posted February 12, 2010 Isn't that what a loop i supposed to do? Why are you thinking that foreach would be a bad solution? However, based upon the code posted I am assuming you are wanting to do multiple string replacements. If so, then you can use arrays as the search and replacement values. The problem you have with the current setup is that your actual search values are enclosed in brackets. So, you would have to modify the values of your search values. $search = array_keys($parts); foreach($search as $key=>$value) { $search[$key] = "{".$value."}"; } echo str_replace($search, $parts, $file) . '<br /><br />'; Spot on cheers for that mate! I must admit I was doubting the foreach() for a while but nope it seems my knolodge is minimal LOL! Cheers mate take care Many thanks James. 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.