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.
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.
$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',
)
Go to menu Search then Replace... .
Make sure Search Mode is Regular Expression
and . matches newline
. matches newline
is NOT checked.
Find what: .*
Replace with: '$0',
Replace All
Then you just need to manually add $array = [
and the closing ];
.
Personally I would do it in PHP like this or something similar to read the file lines into an array:
$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
2. Activate the extended option
3. Put in search \\r\\n
that means carriage return and new line
4. And put in replace ,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.