Quote Escape or special characters in an array value

In my PHP code, I set up a scope so that people can enter their information to be displayed. Information is stored in an array, and I want to make it as flexible as possible.

If I have something like ...

$myArray[]['Text'] = 'Don't want this to fail';

or

$myArray[]['Text'] = "This has to be "easy" to do";

How can I escape from an apostrophe or quote inside an array value?

thank

Edit: since there is only a one-to-one relationship, I changed my array to this structure ...

$linksArray['Link Name'] ='/path/to/link';
$linksArray['Link Name2'] ='/path/to/link2';
$linksArray['Link Name2'] ='/path/to/link3';

In terms of plan, I set up a template with an included file that has these links in a format that someone else (a less technical person) can support. They will have direct access to PHP, and I'm afraid that they can put one or two quotes in the "link name" area and break the system.

Thanks again.

POSSIBLE SOLUTION:

@Tim Cooper.

, ...

$link = "http://www.google.com";
$text = <<<TEXT
Don't you loving "googling" things
TEXT;
$linksArray[$text] = $link;
+3
5

heredoc :

$myArray[]['Text'] = <<<TEXT

Place text here without escaping " or '

TEXT;
+1

PHP . , , ( )... :

$myArray[]['Text'] = "Don't want this to fail";
$myArray[]['Text'] = 'This has to be "easy" to do';

, , \ .

$myArray[]['Text'] = 'Don\'t want this to fail';
$myArray[]['Text'] = "This has to be \"easy\" to do";
+1

, INI XML. INI . XML , .

0

PHP- (, , ), , , . , , , - htmlentities().

Edit: I understand that I may not understand your question. If so, ignore it! :)

0
source

You can use the addslashes ($ str) function to automatically exit quotes.

You can also try htmlentities, which will encode quotes and other special values ​​in HTML entities: http://php.net/manual/en/function.htmlentities.php

0
source

All Articles