如何从表单的文本区域在数组内添加撇号
下面的代码工作正常。
$numbers = array('0018182225252','0012524578125','0015458525458');
$message = $_POST['message'];
$pnum = $numbers;
但是,鉴于这些值将来自每行的文本区域,我如何才能实现类似的代码。
0018182225252
0012524578125
0015458525458
<textarea rows="1" cols="1" id="numbr" name="numbr" wrap="physical"></textarea>
我已经使用爆炸尝试过运气,但我认为我与撇号发生冲突,所以它不起作用..
$num1 = $_POST['numbr'];
$message = $_POST['message'];
$pnum = explode(",", $num1);
$numbers = array($pnum);
没有运气。预先感谢大家!
The below code works fine.
$numbers = array('0018182225252','0012524578125','0015458525458');
$message = $_POST['message'];
$pnum = $numbers;
However, how can I achieve the a similar code given that the values will come from a textarea per line.
0018182225252
0012524578125
0015458525458
<textarea rows="1" cols="1" id="numbr" name="numbr" wrap="physical"></textarea>
I have tried my luck using explode but I think I'm having conflict with the apostrophe so it doesn't work..
$num1 = $_POST['numbr'];
$message = $_POST['message'];
$pnum = explode(",", $num1);
$numbers = array($pnum);
no luck. thanks in advance guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
explode()
的工作原理是将字符串从给定的分隔符。例如,如果您有一个字符串$s = 'a,b,c'
,则使用explode( ',', $s )
会得到array( ' a'、'b'、'c')
。如果您有字符串$s = 'a;b;c'
,那么您可以使用explode( ';', $s )
等等。因此,如果您有一串由换行符分隔的数字,则可以使用换行符 (
\n
) 作为分隔符:请注意,
explode()
返回一个数组因此您不必随后将结果放入另一个数组中。explode()
works by splitting a string from a given delimiter. For example, if you have a string$s = 'a,b,c'
, usingexplode( ',', $s )
givesarray( 'a', 'b', 'c' )
. If you have string$s = 'a;b;c'
, then you'd useexplode( ';', $s )
and so on.So if you have a string of numbers separated by a newline, you'd use the newline character (
\n
) as the delimiter:Note that
explode()
returns an array so you don't have to put the result into another array afterwards.替换
$numbers = $pnum; ( 删除数组()
replace
$numbers = $pnum; ( remove the array()