2

I have the following code

$jsonReplaces = array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"');

and I get the following error message running php4:

Parse error: syntax error, unexpected '/', expecting ')' 

And running php5 is not an option. Any ideas on how to get this working in php4?

Nitrodbz
  • 1,276
  • 1
  • 15
  • 25
  • what are you still doing on PHP4? – Carlos Campderrós Sep 09 '14 at 14:27
  • old server. just temporary. – Nitrodbz Sep 09 '14 at 14:31
  • How are you using this array? – Marc B Sep 09 '14 at 14:31
  • using this array for str_replace() – Nitrodbz Sep 09 '14 at 14:32
  • 1
    This code works fine on [3v4l](http://3v4l.org/j01Mc), what version of 4 are you using? – scragar Sep 09 '14 at 14:32
  • testing it from http://writecodeonline.com/php4/ – Nitrodbz Sep 09 '14 at 14:36
  • Could you check the actual version you will be running on, it's possible the site is wrong(as it would be if someone called strip_slashes on the input). – scragar Sep 09 '14 at 14:43
  • We know it's `"\\"` causing the problem. Is `$jsonReplaces = array("\", "/", "\n", "\t", "\r", "\b", "\f", '"');` an option? It didn't throw an error at http://writecodeonline.com/php4/ - Plus, if we knew what it was used for, we'd probably be able to offer an alternate method. – Funk Forty Niner Sep 09 '14 at 14:46
  • @Fred-ii- That `"\"` can't work. The error is surpressed on `writecodeonline.com`. But when you `var_dump()` the result, you won't get the right result back. His code is correct as it is. I think the bug is getting created by parsing his code, because the website can't handle slashes and backslashes in a right way. Might be `stripslashes()` causing the issue. – Xatenev Sep 09 '14 at 14:50
  • @Xatenev OK, thanks. Well, if OP were to tell us what it was used for, would help us probably find an alternate method. I've no way to test OP's code properly then. – Funk Forty Niner Sep 09 '14 at 14:53
  • 1
    @Fred-ii- true. It would help a lot if we get more informations on **what he want to do** :) – Xatenev Sep 09 '14 at 14:54

3 Answers3

1

I think you have found a bug inside writecodeonline.com . Ive tried various ways of writing and storing something like $jsonReplaces = array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'); and it gives a failure on every try. Seems like the website can't parse that. Might be some issue with stripslashes() (Just a guess). Ive tried same code in another editor and in my local test environment on PHP 4.4.9 and everything is okay.

For example try your code here:

http://sandbox.onlinephpfunctions.com/

Xatenev
  • 6,383
  • 3
  • 18
  • 42
0

I don't have php4 but you can try this, dont escape first item in array

$jsonReplaces = array("\", "/", "\n", "\t", "\r", "\b", "\f", '"' );
Saqueib
  • 3,484
  • 3
  • 33
  • 56
  • `var_dump($jsonReplaces[0]);` after it, for whatever reason that site strips slashes in a strange way. – scragar Sep 09 '14 at 14:40
0

Could you try this please :

$jsonReplaces = array(html_entity_decode("\"), "/", "\n", "\t", "\r", "\b", "\f", '"');

If tehre is a probleme with \\ maybe using html entities could do the trick ...

MARTIN Damien
  • 996
  • 2
  • 15
  • 36