用 preg_replace 替换一些数组(第一行不起作用)
我正在编写一些代码,您可以通过这些代码上传 txt 文件并在数组中读取该文件。现在我想用 preg_replace 更改该数组的某些行,但第一个数组不会更改。
这是代码http://pastebin.com/jkxAE1h5
HTML:
<form method="post" enctype="multipart/form-data">
<input name="my_text[]" type="file" />
<input type="submit" />
PHP:
<?php
$geladene_seite = $_FILES['my_text']['tmp_name'][0];
$array_liste = array(0);
$my_text_file = file($geladene_seite);
foreach ($my_text_file as $single_file) {
$single_file = trim($single_file); // leerzeichen entfernen
if (strlen($single_file) > 0){
$single_file = str_replace(chr(10), '', $single_file);
$single_file = str_replace(chr(13), '', $single_file);
$menge = array_push ($array_liste, $single_file);
}
}
echo '<hr><pre>';
print_r ($array_liste);
echo '</pre>';
$text1 = str_replace($array_liste[1], '<b>'.$array_liste[1].'</b>', $array_liste[10]);
$text2 = str_replace($array_liste[2], '<b>'.$array_liste[2].'</b>', $array_liste[11]);
$text3 = str_replace($array_liste[3], '<b>'.$array_liste[3].'</b>', $array_liste[12]);
echo '<p>'.$text1.'</p>';
echo '<p>'.$text2.'</p>';
echo '<p>'.$text3.'</p>';
?>
示例数据:
text one
text two
text three
this is for description one
this is for description two
this is for description three
header for number one
header for number two
header for number three
many more infos for the text one many more infos for the text one many more infos for the text one many more infos for the text one many more infos for the text one many more infos for the text one
many more infos for the text two many more infos for the text two many more infos for the text two many more infos for the text two many more infos for the text two many more infos for the text two
many more infos for the text three many more infos for the text three many more infos for the text three many more infos for the text three many more infos for the text three many more infos for the text three
最好的问候,史蒂文
i'm scripting some code that you allows you to upload a txt-file an read this in an array. now i want to change some line of this array with preg_replace but the first array will not change.
here is the code http://pastebin.com/jkxAE1h5
HTML:
<form method="post" enctype="multipart/form-data">
<input name="my_text[]" type="file" />
<input type="submit" />
PHP:
<?php
$geladene_seite = $_FILES['my_text']['tmp_name'][0];
$array_liste = array(0);
$my_text_file = file($geladene_seite);
foreach ($my_text_file as $single_file) {
$single_file = trim($single_file); // leerzeichen entfernen
if (strlen($single_file) > 0){
$single_file = str_replace(chr(10), '', $single_file);
$single_file = str_replace(chr(13), '', $single_file);
$menge = array_push ($array_liste, $single_file);
}
}
echo '<hr><pre>';
print_r ($array_liste);
echo '</pre>';
$text1 = str_replace($array_liste[1], '<b>'.$array_liste[1].'</b>', $array_liste[10]);
$text2 = str_replace($array_liste[2], '<b>'.$array_liste[2].'</b>', $array_liste[11]);
$text3 = str_replace($array_liste[3], '<b>'.$array_liste[3].'</b>', $array_liste[12]);
echo '<p>'.$text1.'</p>';
echo '<p>'.$text2.'</p>';
echo '<p>'.$text3.'</p>';
?>
Sample Data:
text one
text two
text three
this is for description one
this is for description two
this is for description three
header for number one
header for number two
header for number three
many more infos for the text one many more infos for the text one many more infos for the text one many more infos for the text one many more infos for the text one many more infos for the text one
many more infos for the text two many more infos for the text two many more infos for the text two many more infos for the text two many more infos for the text two many more infos for the text two
many more infos for the text three many more infos for the text three many more infos for the text three many more infos for the text three many more infos for the text three many more infos for the text three
best regards, steven
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题在这里:
将其更改为:
Your problem is here:
Change it to: