Jump to content

php replace   with a real space..??


john_6767

Recommended Posts

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

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("&nbsp;");
$text = array(" ");
$output = str_replace($text, $html, $_POST['proj_content']);

?>[/code]

Option 1 (Only double space replaced) :
[code]<?php

$html = array(" &nbsp;");
$text = array("  ");
$output = str_replace($text, $html, $_POST['proj_content']);

?>[/code]
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 &nbsp; so i thought it wasn't working.. when i check the db it appears to be entered fine now, thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.