john_6767 Posted January 16, 2007 Share Posted January 16, 2007 i'm trying to replace the that i get from my html editor into real spaces, i have tried the following code with no luck, what can i do to get this to work? I have used variables in the str replace because someone mentioned that may help?[code=php:0]$contentFromPost = $_POST['proj_content'];$contentReplaceThis = " ";$contentReplaceWithThis = " ";$contentForUpdate = str_replace($contentReplaceThis, $contentReplaceWithThis, $contentFromPost);[/code] Quote Link to comment Share on other sites More sharing options...
kobmat Posted January 16, 2007 Share Posted January 16, 2007 try$contentForUpdate = preg_replace('/\ \;/', '', $contentFromPost); Quote Link to comment Share on other sites More sharing options...
john_6767 Posted January 16, 2007 Author Share Posted January 16, 2007 nope that didn't work either Quote Link to comment Share on other sites More sharing options...
kobmat Posted January 16, 2007 Share Posted January 16, 2007 try $contentForUpdate = preg_replace('/\ \;/mi', ' ', $contentFromPost); Quote Link to comment Share on other sites More sharing options...
john_6767 Posted January 16, 2007 Author Share Posted January 16, 2007 nope, that didn't work Quote Link to comment Share on other sites More sharing options...
papaface Posted January 16, 2007 Share Posted January 16, 2007 This should do the job:[code]$contentFromPost = $_POST['proj_content'];$contentReplaceThis = " ";$contentReplaceWithThis = " ";echo ereg_replace($contentReplaceThis,$contentReplaceWithThis,$contentFromPost);[/code] Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted January 16, 2007 Share Posted January 16, 2007 Actually this really isnt a good idea... its better to replace 2 spaces with that way it saves output and makes the code somewhat readable.But its up to you.Option 1 (All spaces replaced) :[code]<?php$html = array(" ");$text = array(" ");$output = str_replace($text, $html, $_POST['proj_content']);?>[/code]Option 1 (Only double space replaced) :[code]<?php$html = array(" ");$text = array(" ");$output = str_replace($text, $html, $_POST['proj_content']);?>[/code] Quote Link to comment Share on other sites More sharing options...
john_6767 Posted January 16, 2007 Author Share Posted January 16, 2007 ok, cheers guys, i just worked it out, looks like all these methods posted here will work ok i was checking the data in a html editor on screen which changes some normal spaces to so i thought it wasn't working.. when i check the db it appears to be entered fine now, thanks! 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.