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??
Related
I'm having the weirdest issue. I've tried referencing other similar answers here, but none seem to fix my issue.
I have the following regex in PHP
/if\s+(?:(.*?)\s*==\s*(?:UrlStatus|DeadURL)|in_array\s*\((?:UrlStatus|DeadURL),\s*(.*?)\s*\))\s*then\s+local\s+arch_text\s+=\s+cfg.messages\['archived'\];(?:(?:\n|.)*?if\s+(?:(.*?)\s*==\s*(?:UrlStatus|DeadURL)|in_array\s*\((?:UrlStatus|DeadURL),\s*(.*?)\s*\))\s*then\s+Archived = sepc \.\.)?/im
It's a messy regex I know, it's supposed to parse code from a module of various versions from different location. It works perfectly in regex101, but preg_match returns false, indicating an error occured. The regex you see is pulled straight from a var_dump. Also pulled from the var_dump is the string being tested. I have included the excerpt that is supposed to match it below.
if is_set(ArchiveURL) then
if not is_set(ArchiveDate) then
ArchiveDate = seterror('archive_missing_date');
end
if "no" == DeadURL then
local arch_text = cfg.messages['archived'];
if sepc ~= "." then arch_text = arch_text:lower() end
Archived = sepc .. " " .. substitute( ```
In the full block of text it takes 81,095 steps to match.
Could it have something to do with that?
Getting a read from preg_last_error(), it returned 6, which maps to the constant PREG_JIT_STACKLIMIT_ERROR.
PHP 7 uses a JIT compiler for preg_match with a small stack size limit. Disabling it allows preg_match to do its job.
This can be done in the php.ini file, or on the fly in the script by using ini_set( 'pcre.jit', false );
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–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> | <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
Recently I've begin moving to sublime text 3 from Netbeans.
I've discovered almost all needed features but still can't find one.
There is a cool feature in Netbeans:
It does the following. If I have such code:
$product = new Product;
$product->someMethod();
I don't need actually to type - and then shift + > to get -> . It's enough just to presss - sign and Netbeans figures out on his own that it should be -> .
The same is applied to array.
I understand that Sublime doesn't do as deep code analysis as Netbeans does.
Of course it would perfect solution if it could figure out like Netbeans does.
But I would happy to replace - sign on numpad keyboard to -> always.
I've tried snippets. It looks like this:
It works ok. But only if it goes as the first symbol in the word.
But then I need to reference an object referencing never goes first.
I can't believe that all people type manually every time - and shift+> to get referencing the object. There must be better way.
Any ideas? How did you tackle this problem?
Looks like there is no silver bullet which would kill any beast.
Though ST is a cool editor it's just editor, it's good for js, scss,css, python where Netbeans sucks but too bad for php.
Probably I would be happy with ST for PHP if I didn't know that you can get more boosting using full-blown IDE.
So frontend development will be carried on ST and backend on Netbeans.
Edit
Of course I tried the whole bunch of available plugins. This is the list of tried:
To replace the - key with -> in all situations in Sublime Text (meaning if you want to write, for example 1 - 2, you would have to type 1 -backspace 2, you can do the following:
From the Preferences menu in Sublime Text
Click Keybindings - User
Write [{ "keys": ["-"], "command": "insert", "args": { "characters": "->" } }] (note that this assumes that you don't already have anything in the user keybinding file. If you do, before the ] at the end of the file, type , and the above without the enclosing [ and ] characters. The file needs to be a valid JSON array of keybindings.)
Save it
Try typing - and see the magic
You may be able to do some magic with contexts to get this keybinding only for PHP syntax files, or you could just write a simple Python plugin that your keybinding would execute, which would enter - in the document if it is not a PHP file and -> if it is.
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.
I have just installed rsslounge 1.7 but I am experiencing a wierd issue.
When rsslounge loads, everything seems ok, but when the rss elements are refreshed (for instance I click on a category on the left), the rss elements's contents turn into "?". This behaviour is happening on Greek characters only.
How can I fix this?
I came across the same problem and fixed it by changing a single line:
http://code.google.com/p/rsslounge/source/browse/trunk/application/controllers/ItemController.php#80
Replace it with the following one:
'html' => $this->view->render('item/list.'.Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->getViewSuffix()),
Basically, you remove the utf_encode/decode calls...
This isn't a perfect full solution (other small problems remain), but you at least get a functional rss reader ;).
Edit: Go to config/config.ini and add the following line:
resources.db.params.charset = "utf8"
This should fix everything (your old rss items will not be printed correctly though).