Jump to content

Quotation mark issue


kurt.santo

Recommended Posts

I use include files with content as:

$page_title = "page title";$page_content = <<<EOT<h1>heading</h1><p>my web page's text</p>EOT;

It is all working fine, but I just noticed that in the files where there is a "'" the text afterwards is shown in red in my code. I thought I need to escape only if there is a single or double quotation inside anohter quotation? Am I wrong with that assumption? I tried to escape the single quotation mark, but code (text) afterwards still rendered in red. As I said it displays fine on web page...Kurt

Link to comment
Share on other sites

Using HEREDOC you should be able to put quotation marks and inverted commas no problem. Maybe your syntax highlighter's rules are badly written.

Link to comment
Share on other sites

Are you using ConTEXT? The syntax highlighting rules for ConTEXT aren't powerful enough to highlight a PHP/HTML document correctly (that may be fixed, as the auction to buy and open-source ConTEXT ends tomorrow). But when I have code like this:

<div>You didn't fill out your name</div><?php.....?>

The apostraphe in "didn't" screws up the highlighter. So I just add a comment with another one to get the highlighting back on track.

<div>You didn't fill out your name</div> <!-- ' can add one here --><?php // ' or here.....?>

Link to comment
Share on other sites

Are you using ConTEXT? The syntax highlighting rules for ConTEXT aren't powerful enough to highlight a PHP/HTML document correctly (that may be fixed, as the auction to buy and open-source ConTEXT ends tomorrow). But when I have code like this:
<div>You didn't fill out your name</div><?php.....?>

The apostraphe in "didn't" screws up the highlighter. So I just add a comment with another one to get the highlighting back on track.

<div>You didn't fill out your name</div> <!-- ' can add one here --><?php // ' or here.....?>

I use Dreamweaver. Was always very happy with it, but since I started going into dynamic sites (php) had some problems... Will try to comment and see what happens...Kurt
Link to comment
Share on other sites

I use Dreamweaver. Was always very happy with it, but since I started going into dynamic sites (php) had some problems... Will try to comment and see what happens...Kurt
I commented it out and it did the job. Not sure if I will do it for whole site as it would be a lot of work. Guess main thing is that is works...Another question:I just noticed that I include a file the top with "ob_start();", but I never end the output buffering anywhere in my code... As I said the site works, but this is probably not a good idea to leave it this way? My error handler redirects, so there is no error messages to buffer for a later display and content (from an include) is called via "echo $page_content;". Seems to me that output buffering should not be used at all (I put it in first as I wanted to buffer error messages to be displayed in content area, but changed my mind later on as I could not work it out;-)). What do you think?Kurt
Link to comment
Share on other sites

I don't really use output buffering for anything, it seems like for any problem that output buffering solves you can rework the application so that it's not an issue.
How do you approach the reworking of an application? I took the output buffering out, but then it said that the headers were already sent. The code is:
<?phpob_start();include('inc/handle.php');session_start();$def_lang = 'en';if (isset($_GET['lang']) && ereg('[a-z]{2}(\-[a-z]{2})?', $_GET['lang']) && is_file("inc/{$_GET['lang']}/nav/globalNav.htm"))  $lang = $_GET['lang'];elseif (isset($_SESSION['lang']))  $lang = $_SESSION['lang'];else  $lang = $def_lang;$_SESSION['lang'] = $lang;$globalNav = "inc/{$lang}/nav/globalNav.htm";$articleNav = "inc/{$lang}/nav/articlesNav2.htm";$legalNav = "inc/{$lang}/nav/legalNav2.htm";?>

I just do not get it in my head what this "headers sent" things does/means...?Kurt

Link to comment
Share on other sites

Check the PHP tips thread, there's an explanation of the error there.
Had a read through your thread (thank you, great stuff!), but still not sure what to do. The problem is that my handler sends the header info, but if I do not include my handler at top of script it won't handle any problems with my php code and just gives a jumbled mess when there is an issue (I use a redirect to let user know that there is a problem).Kurt
Link to comment
Share on other sites

If you have a redirect in your error handler then you pretty much have to use output buffering, because an error could conceivably happen at any time, even while sending output. The only way to remove output buffering with something like that is make sure you do all of your PHP processing that may result in an error before you send any output. That would mean that any PHP code mixed in with the HTML would only be output statements where you can guarantee it's not going to cause an error, not processing statements that may result in an error.

Link to comment
Share on other sites

If you have a redirect in your error handler then you pretty much have to use output buffering, because an error could conceivably happen at any time, even while sending output. The only way to remove output buffering with something like that is make sure you do all of your PHP processing that may result in an error before you send any output. That would mean that any PHP code mixed in with the HTML would only be output statements where you can guarantee it's not going to cause an error, not processing statements that may result in an error.
Then it seems I have to use output buffereing in this case. If I have all processing before my error handling (and therefore the redirection), the error handler won't catch errors and the handler becomes obsolete. Got this one!But when I begin output buffereing at top of my page, but do not end it at bottom of my page (which I did without realising): is this not causing any problems? My pages display without problems. I would have assumed this is not the case?Kurt
Link to comment
Share on other sites

What does it mean to send the buffer?
It sends it to the browser so the browser can display it.
Is it then ok to leave it as it is (without ending the output buffering)?
Yes
Link to comment
Share on other sites

But the browser does not display it when you have no intent to do so (and there is no programming indicating the contrary)?
But then there wouldn't be anything in the output buffer in the first place. If the OB has content buffered, it will send it to the client at script termination (not sure about when die() is used though).
Link to comment
Share on other sites

But then there wouldn't be anything in the output buffer in the first place. If the OB has content buffered, it will send it to the client at script termination (not sure about when die() is used though).
Guess I have to read up a bit more about output buffering. Am a bit lost here... Kind of just want to make sure my user do not see any error messages apart from the ones I provide (therefore I have to use output buffering somehow as my error handler sends the header information - it is the first in my script and needs to be, so it tackles problems)...Kurt
Link to comment
Share on other sites

  • 3 weeks later...

Archived

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

×
×
  • Create New...