Why is this html code not correctly interpreted? - php

I am a bit curious about this HTML code (Firebug's view):
<td>1–1 of 1 record found matching your query (RSS | history):</td>
I was trying to install refbase. I used the snapshot version because of SQL problems with the current release. While testing I got this view (Firebug console is opened on purpose to show how the code is interpreted, but I see the same on chromium for instance):
.
.
Then I clicked in the firebug view and added a single space character somewhere, and did escape to let it as it was. But after having added the space, the view changed into this:
.
.
So basically I changed nothing but the code is now correctly interpreted. That's really weird. I googled a bit about this, but I think I might not have found the appropriate keywords.
Could someone explain me the reason behind this weird behaviour and how to fix it? BTW this Here is the complete php source producing this page. Look on line 796.
EDIT:
Thanks to LGSon I noticed that it is a Firebug's trap: it interprets the & stuff to show nice html code and then when you edit-it, it becomes the real code. That's tricky indeed, but when checking page source you can see the real HTML:
<td>1&#8211;1 of 1 record found matching your query (<a href="rss.php?where=title%20RLIKE%20%22physics%22" title="track newly added records matching your current query by subscribing to this RSS feed">RSS</a>&nbsp;|&nbsp;<a href="query_history.php" title="recall a previous query from your current session">history</a>):</td>

It should be 1–1
Sample
1–1

Related

How to correctly make conditions in TinyButStrong?

I have to make a template in the TinyButStrong language, but I have no access to the PHP side. I'm just able to modify my template and to upload it on my ERP.
Anyway, the PHP side is working well.
I tried to put an if statement in my ODT template file, but when rendering it doesn't work.
My condition:
[if [tab.product_type]!=1; then ‘[tab.product_ref]’; else ‘0’; block=table:table-row]
I verified value of tab.product_type, and the value is 0 or 1.
I tried many syntaxes, but none is working well. The only thing that it shows is:
.
Where did I make a mistake? I really don't understand, because I tried many syntaxes and I still get this line.
Little update :
I saw that the "when" is more adapted to this usage.
I found a syntax but I'm still having bad results. I made this :
[tab.product_ref;block=table:table-row;when [tab.product_type]!=1]
Anyway, it's giving me lines where tab.product_type is 1.
Why ?? I really don't understand how this language works...

Stubborn Byte Order Mark in cakephp

I know there are a lot of questions on this topic, I've been reading and trying different ideas for hours.
I'm fetching data using the Dropbox api, which works fine, but it's slow.
So I'm moving this fetch to ajax.
The json response has the ever popular invisible question mark appended to the end of the string... after the closing square bracket.
.....}]?
This makes the json object invalid and none of the regular functions work on invalid json.
It's there when I load the page direct, but goes away when I set autoRender to false. So I got it working.... but, I would like to find this little POS and remove it before it shows up randomly in the future. It took hours to figure out that this was problem because it's invisible!
I can use Notepad++ to eradicate the little beasty, but I can't find it!
I've tried the following...
grep -rlI $'\xEF\xBB\xBF' .
Total Commander -> go to project's root dir -> find files (alt+f7) -> file types . -> Find text "EF BB BF" -> check 'Hex' checkbox -> search
search in project for charset=iso-8859
Tried this hack
$response = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $response);
I use Netbeans which near as I can tell is worthless for this problem.
Keep in mind, this is Cakephp 2.3, so there are about 3.7 million files that get loaded.
How do you find these things??

Not able to parse this json

I am trying to parse the json output from
http://www.nyc.gov/portal/apps/311_contentapi/services/all.json
And my php json_decode returns a NULL
I am not sure where the issue is, I tried running a small subset of the data through JSONLint and it validated the json.
Any Ideas?
The error is in this section:
{
"id":"2002-12-05-22-24-56_000010083df0188b4001eb56",
"service_name":"Outdoor Electric System Complaint",
"expiration":"2099-12-31T00:00:00Z",
"brief_description":"Report faulty Con Edison equipment, including dangling or corroded power lines or "hot spots.""
}
See where it says "hot spots." in an already quoted string. Those "'s should've been escaped. Since you don't have access to edit the JSON perhaps you could do a search for "hot spots."" and replace it with \"hot spots.\"" like str_replace('"hot spots.""', '\\"hot spots.\\""\, $str); for as long as that's in there. Of course that only helps if this is a one time thing. If the site continues to make errors in their JSON output you'll have to come up with something more complex.
What I did to identify the errors in the JSON ...
Since faulty quoting is the first thing to look for, I downloaded the JSON to a text file, opened in a text editor (I used vim but any full featured editor would do), ran a search and replace that removed all characters except double-quote and looked at the result. It was clear that correct lines should have 4 double-quotes so I simply searched for 5 double-quotes together and found the first bad line. I noted the line number and then undid the search and replace to get the original file back and looked at that line. This gives you what you need to get the developers of the API to fix the JSON.
Writing code to automatically fix the bad JSON before giving it to json_decode() would be quite a bit harder but doable using techniques like those in another answer.
According to the PHP manual:
In the event of a failure to decode, json_last_error() can be used to determine the exact nature of the error.
Try calling it to see where the error is.

strange thing, ajax response includes whitespace

I ave several JS functions that call different php files with $.ajax jquery method... yesterday everything was fine, but after cleaning up my code, i don't know what i did, but now the ajax response is like "[space]data" instead of "data"..
i could use a trim function in Js but i want to fix the source of the problem...
all my php files have the missing last ?> in order to avoid that, and before <?php i'm sure, just checked, there is no space...
how come did I introduce this error? is the server? the browser?
The funny thing is that yesterday i cleaned my code with JSLINT..! bad idea..
thanks
When I had the same problem it was just a carriage return or space after the closing PHP tag, a surprisingly easy thing to introduce by accident.
Make sure you open the PHP tag at the start of the first line of your script, close it at the end and delete everything after the closed tag (should be easy to spot in a good editor).
I can see no reason why not closing your PHP tag wouldn't just be really annoying.. but thats just me!
I know I'm late this this thread, found it because I had the same issue. I was able to confirm that the although you may clear all the spacing in your callback function it is still possible to get these white-space/carriage returns in your response text (you can even see this in chrome developer tools under the "Network" tab).
So I tested and found that if you put ob_clean(); at the top of your callback function then it clears any of those spaces. I don't know much about this function just that it was mentioned in the codex (http://codex.wordpress.org/AJAX_in_Plugins#Debugging). Hope that helps anyone else that find there way here because of the same issue
If your response from the server includes the extra space, then the php code is the cause. If your response does not include the extra space, then the problem must be in javascript.
Use Fiddler to examine the actual response from the server to see if it really has the space in it. You'll then know for sure if the problem is with PHP or JS. Then you can post the relevant code.

Why will this text in the browser source code not show on the screen?

I am modifying an existing source code viewer script in PHP that I found on the web. It is to store source code in a nice category fashion.
I am having a problem now though. Below is a screen shot of me viewing the source code in Firefox, you can see the part that is supposed to show on the screen but for some reason it is not showing on the screen, it is showing up in the source of the page though so I am really confused as to why I cannot view it in the browser? You will also notice that the text color is Pink/Purple color. The part inside the
Please not that it is not any CSS that is making it hidden or anything.
alt text http://img2.pict.com/cd/d2/74/2663869/0/screenshot2b209.png
<?php is considered as an opening tag, which is only closed by ?> ; and the browser doesn't display tags themselves.
The <td> tags, for instance, are not displayed by your browser : they are interpreted to create a table ; it's the same with the <?php tag... But it doesn't generate any output, as the browser doesn't know what to do with it.
If you want to actually display your portion of PHP code in the HTML page, you have to encode it to HTML entities :
< should be converted to <
> should be converted to >
& should be converted to &
" should be converted to "
This way, you'll get some valid HTML, and not "things looking as HTML tags".
But note that if you want that portion of PHP code to actually be interpreted (So the query to the database is executed, and generates some output), you'll have to re-configure your webserver, so PHP code is interpreted : you should not see the PHP code on the browser-side.
Processing Instructions are not shown in the browser.
That is not "browser source code". It is PHP source code that superficially looks like HTML. This is not a petty distinction, but actually fundamental if you want to understand how things work. If you are viewing that exact code in Firefox, it means you're viewing the PHP as text, not rendered HTML.
So something is wrong with your PHP server setup.

Categories