Jump to content

  breaking PHP script...


Michael4172

Recommended Posts

[!--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.
[!--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...
[!--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.
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?
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]
[!--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.
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.
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\" /]
[!--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 :)

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.