[英]Convert regular text to array using notepad++
i am trying to use notepad++ to select a new line and replace it with this " ',' ", so that i can use it in PHP as an array and then work on it, but i dont know what regular expression to use in the search and replace form. 我正在尝试使用notepad ++选择新行并将其替换为“”,“”,以便我可以在PHP中将其用作数组,然后对其进行处理,但是我不知道在搜索并替换表格。
Below is what i have 以下是我所拥有的
Tunneller
Turf Accountant
Turkey Farmer
Turner
Tutor
Typesetter
Typewriter Engineer
Typist..
and you want to arrive at something like this - array like syntax to feed into my php document. 并且您想要得到类似这样的内容-像语法这样的数组,可以输入到我的php文档中。
$array = [Tunneller','Turf','Accountant','TurkeyFarmer','Turner','Tutor','Typesetter','Typewriter Engineer','Typist']
thanks. 谢谢。
To turn your input into a quoted, comma separated list (transform ALL lines from text
to 'text',
) 要将输入内容转换为带引号的逗号分隔列表(将所有行从
text
转换为'text',
)
Go to menu Search then Replace... . 转到菜单搜索,然后替换...。
Make sure Search Mode is Regular Expression
and . matches newline
确保搜索模式为
Regular Expression
和. matches newline
. matches newline
is NOT checked. . matches newline
。
Find what: .*
查找内容:
.*
Replace with: '$0',
替换为:
'$0',
Replace All
Then you just need to manually add $array = [
and the closing ];
然后,您只需要手动添加
$array = [
和结束符];
. 。
Personally I would do it in PHP like this or something similar to read the file lines into an array: 就我个人而言,我会在PHP中这样或类似地将文件行读入数组中:
$array = file('/path/to/file.txt', FILE_IGNORE_NEW_LINES);
If you really need to print it as an array definition for some reason: 如果由于某种原因确实需要将其作为数组定义打印:
echo '<pre>$array = ' . var_export($array, true) . '</pre>';
1. Hit Ctrl + H 1. 按Ctrl + H
2. Activate the extended option 2.激活扩展选项
3. Put in search \\r\\n
that means carriage return and new line 3.输入搜索
\\r\\n
表示回车和换行
4. And put in replace ,
4.放回原处
,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.