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] Link to comment https://forums.phpfreaks.com/topic/34347-php-replace-nbsp-with-a-real-space/ Share on other sites More sharing options...
kobmat Posted January 16, 2007 Share Posted January 16, 2007 try$contentForUpdate = preg_replace('/\ \;/', '', $contentFromPost); Link to comment https://forums.phpfreaks.com/topic/34347-php-replace-nbsp-with-a-real-space/#findComment-161616 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 Link to comment https://forums.phpfreaks.com/topic/34347-php-replace-nbsp-with-a-real-space/#findComment-161650 Share on other sites More sharing options...
kobmat Posted January 16, 2007 Share Posted January 16, 2007 try $contentForUpdate = preg_replace('/\ \;/mi', ' ', $contentFromPost); Link to comment https://forums.phpfreaks.com/topic/34347-php-replace-nbsp-with-a-real-space/#findComment-161654 Share on other sites More sharing options...
john_6767 Posted January 16, 2007 Author Share Posted January 16, 2007 nope, that didn't work Link to comment https://forums.phpfreaks.com/topic/34347-php-replace-nbsp-with-a-real-space/#findComment-161656 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] Link to comment https://forums.phpfreaks.com/topic/34347-php-replace-nbsp-with-a-real-space/#findComment-161667 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] Link to comment https://forums.phpfreaks.com/topic/34347-php-replace-nbsp-with-a-real-space/#findComment-161683 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! Link to comment https://forums.phpfreaks.com/topic/34347-php-replace-nbsp-with-a-real-space/#findComment-161688 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.