[英]How can I echo an array in an html input text value attribute
I have the following scenario: 我有以下情况:
I have a PHP array which has tags on it, they can be between 4 and 7. 我有一个上面带有标签的PHP数组,它们可以在4到7之间。
And I need to put that PHP Array in an input type text separated by commas on the value attribute. 而且我需要将该PHP Array放在value属性的逗号分隔的输入类型文本中。 Any idea how can I do this?
知道我该怎么做吗?
The input text is a plugin for tags, which is http://timschlechter.github.io/bootstrap-tagsinput/examples/bootstrap3/ 输入文本是标签的插件,该插件是http://timschlechter.github.io/bootstrap-tagsinput/examples/bootstrap3/
Any help would be appreciated! 任何帮助,将不胜感激!
This is my PHP code: 这是我的PHP代码:
while($dataTagsToPut = $resultTags->fetch_assoc()){
array_push($stringTags, $dataTagsToPut['SOLUTION_TAGS_NAME']);
}
This is my HTML: 这是我的HTML:
<input type="text" id="solutionTags" value="<?php echo htmlspecialchars(??whatgoeshere); ?>" name="solutionTags">
One simple way: 一种简单的方法:
echo implode(',', array_map('htmlspecialchars', $stringTags));
array_map
applies a function to each element and gives you the results from each call. array_map
将函数应用于每个元素,并为您提供每次调用的结果。 Then you can implode
the array to turn it into a string. 然后,您可以内
implode
数组以将其转换为字符串。
Should also work the other way around in this case ( implode
the array, then call htmlspecialchars
on the resulting string), since ,
isn't special in HTML. 也应努力的其他方式在这种情况下(约
implode
的阵列,然后调用htmlspecialchars
上得到的字符串),因为,
是不是在HTML特殊。
尝试这个:
<?php echo htmlspecialchars(implode($stringTags)); ?>
Implode the array. 放大阵列。
implode(',', $stringTags)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.