Jump to content

Archived

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

Michael4172

  breaking PHP script...

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?

Share this post


Link to post
Share on other sites
Please post the code that is causing the problem. I use \  in PHP without problems.

Ken

Share this post


Link to post
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.

Share this post


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

Share this post


Link to post
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...

Share this post


Link to post
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');

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
you can replace the ' with & # 3 9 ; using str_replace (without the spaces)

This will print out the ' in any browser.

Share this post


Link to post
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.

Share this post


Link to post
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\" /]

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

×

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.