String to array then back to string
Moderator: General Moderators
String to array then back to string
I'm trying to take a string and put it into an array (done that), now i'm looping through the array using foreach and replacing certain values (got that), now how do I put this back into a string? It's creating like a multidimential array, which is not what I want.. im kinda at a loss
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
foreach($getBeginning as $word){
$original = $word;
$word = mysql_escape_string($word);
$db->sql_query("select synonym from synonyms where word = '$word' limit 1");
while($row = $db->fetch_array()){
$synonym = $row['synonym'];
$synonymWord = str_replace($word, $synonym, $synonymWord);
}
$new[$original] = $synonymWord;
}
print_r($new);- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
you forgot to include the array, but it looks like a simple implode() should suffice.
Last edited by John Cartwright on Sat Mar 17, 2007 8:51 pm, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: