Jump to content


Photo

  breaking PHP script...


  • Please log in to reply
13 replies to this topic

#1 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 June 2006 - 03:43 PM

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

nbsp;

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?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 June 2006 - 03:47 PM

Please post the code that is causing the problem. I use \  in PHP without problems.

Ken

#3 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 June 2006 - 03:52 PM

[!--quoteo(post=381444:date=Jun 8 2006, 11:47 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 8 2006, 11:47 AM) View Post[/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:

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>';

The WYSIWYG editor auto inserts that bit.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 June 2006 - 04:08 PM

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

#5 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 June 2006 - 04:17 PM

[!--quoteo(post=381455:date=Jun 8 2006, 12:08 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 8 2006, 12:08 PM) View Post[/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...


#6 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 08 June 2006 - 04:47 PM

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');

NoGray.com


#7 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 08 June 2006 - 05:12 PM

[!--quoteo(post=381458:date=Jun 8 2006, 09:17 AM:name=BigMike)--][div class=\'quotetop\']QUOTE(BigMike @ Jun 8 2006, 09:17 AM) View Post[/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:

<?php

echo "something"
someFuntion();

?>

[!--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.
~ D Kuang

#8 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 June 2006 - 06:28 PM

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

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

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:

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

But it still breaks when it gets to n't. Any ideas on that one?

#9 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 08 June 2006 - 06:38 PM

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]
~ D Kuang

#10 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 June 2006 - 08:28 PM

[!--quoteo(post=381529:date=Jun 8 2006, 02:38 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 8 2006, 02:38 PM) View Post[/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.


#11 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 08 June 2006 - 08:45 PM

you can replace the ' with & # 3 9 ; using str_replace (without the spaces)

This will print out the ' in any browser.

NoGray.com


#12 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 June 2006 - 08:55 PM

I tried this to no avail.

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

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

#13 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 08 June 2006 - 09:12 PM

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

$string = htmlentities($string, ENT_QUOTES);

[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\" /]
~ D Kuang

#14 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 09 June 2006 - 08:29 PM

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

$string = htmlentities($string, ENT_QUOTES);

[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 :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users