Array implode with '<', odd behavior

 $b = array("one", "two", "three"); $z = implode('<', $b); var_dump($z); 

outputs: line (13) "one

can someone explain this.

PHP 5.4.4

+4
source share
3 answers

view original html result, real result:

 string(13) "one<two<three" 

as eis mentioned:

This is what he should do. You look at it in your browser, where it does not show the results as is, but tries to make it as HTML.

therefore, if you want to see it as plain text, the html tags tag filter:

 <?php $b = array("one", "two", "three"); $z = implode('<', $b); $z = htmlspecialchars($z); var_dump($z); 
+3
source
 >php implode.php string(13) "one<two<three" 

This is what he should do. You look at it in your browser, where it does not show the results as is, but tries to display it as HTML.

+2
source

If you want to print the text as html, use a special encoding:

 <?php $ar = array('one', 'two'/** ... **/); print implode('&lt;', $ar); 

To view all special encodings: http://www.degraeve.com/reference/specialcharacters.php

0
source

Source: https://habr.com/ru/post/1443991/


All Articles