Jump to content

  breaking PHP script...


Michael4172

Recommended Posts

I have a script hat works fine, but whenmy WYSIWYG editor inserts in

[code]nbsp;[/code]

Into the echo portion of the script, it breaks it due to having the ; in the nbsp portion. Any ideas of how to overcome this since I can't make the WYSIWYG editor stop inserting that?
Link to comment
Share on other sites

[!--quoteo(post=381444:date=Jun 8 2006, 11:47 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 8 2006, 11:47 AM) [snapback]381444[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Please post the code that is causing the problem. I use \  in PHP without problems.

Ken
[/quote]

Well my question is how to auto insert \ whenever   comes up. Here's a sample:

[code]
echo '<span class="par_1"><p>The single most important criterion used for selection is that the prospective company  should be able to meet and maintain the standards&nbsp;expected by the end users.</p>';
[/code]

The WYSIWYG editor auto inserts that bit.
Link to comment
Share on other sites

[!--quoteo(post=381455:date=Jun 8 2006, 12:08 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 8 2006, 12:08 PM) [snapback]381455[/snapback][/div][div class=\'quotemain\'][!--quotec--]
The "\" in my post was an attempt to get this forum not to interpret the '\&nbsp;' not that I use it in my scripts.

Your sample should be fine. Why do you think it is breaking PHP?

Ken
[/quote]

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in
/home//htdocs/example.php on line

That's the only ; on that line...
Link to comment
Share on other sites

The line number is not accurate all the time, usually the error is around that line, so check the lines above and under.

if you want ot replace the "&nbsp;" use the str_replace("&nbsp;", " ", 'Your text');
Link to comment
Share on other sites

[!--quoteo(post=381458:date=Jun 8 2006, 09:17 AM:name=BigMike)--][div class=\'quotetop\']QUOTE(BigMike @ Jun 8 2006, 09:17 AM) [snapback]381458[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in
/home//htdocs/example.php on line

That's the only ; on that line...
[/quote]
I guess there is an un-terminated line; like:

[code]<?php

echo "something"
someFuntion();

?>[/code]

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in blahblahblah.php on line 4[/quote]

But it could be anything. Check the lines near it for missing code.
Link to comment
Share on other sites

aha...I finally see what the problem was. Here's a sample:

[code]
echo 'If you haven't been here long, you may want to leave.';
[/code]

Thus the ' in haven't was causing the problem. I tried the string replace earlier to auto do away with these and put a \' before them all, but haven't figured that out yet. I have it as:

[code]
$text = str_replace("'", "\'", 'If you haven't been here long, you may want to leave.');
[/code]

But it still breaks when it gets to n't. Any ideas on that one?
Link to comment
Share on other sites

You can use addslashes() or htmlentities with ENT_QUOTES/ENT_NOQUOTES:

[a href=\"http://www.php.net/addslashes\" target=\"_blank\"]http://www.php.net/addslashes[/a]
[a href=\"http://www.php.net/htmlentities\" target=\"_blank\"]http://www.php.net/htmlentities[/a]
Link to comment
Share on other sites

[!--quoteo(post=381529:date=Jun 8 2006, 02:38 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 8 2006, 02:38 PM) [snapback]381529[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can use addslashes() or htmlentities with ENT_QUOTES/ENT_NOQUOTES:

[a href=\"http://www.php.net/addslashes\" target=\"_blank\"]http://www.php.net/addslashes[/a]
[a href=\"http://www.php.net/htmlentities\" target=\"_blank\"]http://www.php.net/htmlentities[/a]
[/quote]

I don't want the / to appear. If I do either of those it actually appears.
Link to comment
Share on other sites

I tried this to no avail.

[code]
<?php
$text = str_replace("'", "'", 'If you haven't been here long, you may want to leave.');
echo $text;
?>
[/code]

I regularly have things like <div id = "blah"> is the reason I rather use single quotes as oppose to the double on the end.
Link to comment
Share on other sites

str_replace should do, but you can also use htmlentities or htmlspecialchars with ENT_QUOTES:

[code]$string = htmlentities($string, ENT_QUOTES);[/code]

[a href=\"http://www.php.net/htmlentities\" target=\"_blank\"]http://www.php.net/htmlentities[/a]
[a href=\"http://www.php.net/htmlspecialchars\" target=\"_blank\"]http://www.php.net/htmlspecialchars[/a]

They will replace " ' " with & #039;

Post #625, that is 25^2 or 5^4. I like this number [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
Link to comment
Share on other sites

[!--quoteo(post=381601:date=Jun 8 2006, 05:12 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 8 2006, 05:12 PM) [snapback]381601[/snapback][/div][div class=\'quotemain\'][!--quotec--]
str_replace should do, but you can also use htmlentities or htmlspecialchars with ENT_QUOTES:

[code]$string = htmlentities($string, ENT_QUOTES);[/code]

[a href=\"http://www.php.net/htmlentities\" target=\"_blank\"]http://www.php.net/htmlentities[/a]
[a href=\"http://www.php.net/htmlspecialchars\" target=\"_blank\"]http://www.php.net/htmlspecialchars[/a]

They will replace " ' " with & #039;

Post #625, that is 25^2 or 5^4. I like this number [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
[/quote]

Ok thanks I shall give that a try and play with it some :)
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.