'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.
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.
Solution 1:[1]
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 Expressionand. matches newlineis 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>';
    					Solution 2:[2]
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 ,
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | |
| Solution 2 | 

