Reputation: 161
Learning regex in PHP. Here's my code:
header('Content-type: text/plain; charset=utf-8');
$lines = file('datatest.txt');
$lines = preg_grep("/word/", $lines); //finds words that I need, including numbers
$lines = preg_replace('/\d/', '', $lines); //replaces all numbers with ''
foreach ($lines as $name) {
echo "$name";
}
I have a lined text, every line starts with nubmer, for example:
1.1. Name
2.0. Name2
2.3. Name3
Removed digits, but comma stays, now it looks like this:
.. Name
.. Name2
.. Name3
Thanks!
Upvotes: 2
Views: 41
Reputation: 1317
Try this: This will remove numbers and dot only from the starting of the string
$lines = preg_replace('/^\s*[\d\.]+/', '', $lines);
Upvotes: 0
Reputation: 785856
You can use:
$lines = preg_replace('/[\d.]+/', '', $lines); //replaces all numbers with ''
Upvotes: 1