pibebueno Posted January 27, 2010 Share Posted January 27, 2010 The idea is that "% 1 $ s" is replaced by"%1$s". Very simple but does not go =( <?php $linea = "% 1 $ s"; $linea = ereg_replace("% 1 $ s","%1$s", $linea); echo $linea; ?> Please if anyone knows what I did not do well might help me? Quote Link to comment https://forums.phpfreaks.com/topic/190041-replace-a-string-the-code-does-not-go-well-written-but/ Share on other sites More sharing options...
taquitosensei Posted January 27, 2010 Share Posted January 27, 2010 can you just remove the spaces? $linea="% 1 $ S"; $linea=str_replace(" ","", $linea); Quote Link to comment https://forums.phpfreaks.com/topic/190041-replace-a-string-the-code-does-not-go-well-written-but/#findComment-1002635 Share on other sites More sharing options...
roopurt18 Posted January 27, 2010 Share Posted January 27, 2010 $ has a special meaning inside double-quoted strings. $s = '1234'; echo "asdf$s"; echo "\n"; echo 'asdf$s' Quote Link to comment https://forums.phpfreaks.com/topic/190041-replace-a-string-the-code-does-not-go-well-written-but/#findComment-1002640 Share on other sites More sharing options...
pibebueno Posted January 27, 2010 Author Share Posted January 27, 2010 Thnk you guys but don't work on ereg_replace. please help :'( <?php $Cadena='$ s'; $CadenaMod=ereg_replace('$ s','$s',$Cadena); echo $CadenaMod; ?> Quote Link to comment https://forums.phpfreaks.com/topic/190041-replace-a-string-the-code-does-not-go-well-written-but/#findComment-1002716 Share on other sites More sharing options...
Alex Posted January 27, 2010 Share Posted January 27, 2010 Use str_replace instead. Quote Link to comment https://forums.phpfreaks.com/topic/190041-replace-a-string-the-code-does-not-go-well-written-but/#findComment-1002717 Share on other sites More sharing options...
pibebueno Posted January 28, 2010 Author Share Posted January 28, 2010 Than! <?php $antes = array('$ s'); $despues = array('$s'); $text = '$ s jlkhdsakjdshkajdshkasjdh'; $output = str_replace($antes, $despues, $text); echo $output; ?> Quote Link to comment https://forums.phpfreaks.com/topic/190041-replace-a-string-the-code-does-not-go-well-written-but/#findComment-1002732 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.