0

I have a text file with many different URL typed in the text.

For example:

file:///g:/somepath/subpath/file.txt /somepath/subpath/file.txt Http://www.domain.at/path/file.txt 

I need them to be extracted from the file. In the text file there is no HTML, so I cannot search for something like href.

Is there a RegEx for PHP that I can use?

3
  • 1
    There are several, but no human knows them by heart. Ask Google. Commented Dec 15, 2011 at 20:48
  • 1
    If each is on a separate line or has the same separator, just read the file and explode it. Commented Dec 15, 2011 at 21:01
  • the links are in the middle of the text, there is no special sign to explode them. Commented Dec 16, 2011 at 6:42

1 Answer 1

1

Post entire file if you want more help. From given...

<?php $string = 'file:///g:/somepath/subpath/file.txt dasdsaddasdf dsafddsad /somepath/subpath/file.txt Http://www.domain.at/path/file.txt adsadsadasd '; preg_match_all('#([\S]+)\.txt#is', $string, $matches); print_r($matches[1]); ?> 

Result

Array ( [0] => file:///g:/somepath/subpath/file [1] => /somepath/subpath/file [2] => Http://www.domain.at/path/file ) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.