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
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]
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.