Page 1 of 1

how would I do this?

Posted: Sun Apr 16, 2006 12:31 pm
by elecktricity
I think an ereg replace would do this but I have a huge file basicially looking like this:
100-200xx10.jpg">100-200xx10.jpg</A> 10-Apr-2006 16:38 3k
100-200xx11.jpg">100-200xx11.jpg</A> 10-Apr-2006 16:49 4k
100-200xx16.jpg">100-200xx16.jpg</A> 10-Apr-2006 16:52 16k
and I would like it to be something like:
100-200xx10.jpg
100-200xx11.jpg
100-200xx16.jpg
I think a ereg replace would do this but it dosnt seem to be

Code: Select all

<?PHP
$string = '100-200xx10.jpg">100-200xx10.jpg</A>      10-Apr-2006 16:38     3k  
100-200xx11.jpg">100-200xx11.jpg</A>      10-Apr-2006 16:49     4k  
100-200xx16.jpg">100-200xx16.jpg</A>      10-Apr-2006 16:52     16k  ';
echo ereg_replace('">[a-zA-Z0-9.<>/- ]', '', $string);
?>
this dosnt seem to work, what should I do?

Posted: Sun Apr 16, 2006 12:38 pm
by feyd
what's a full line from this file look like?

Posted: Sun Apr 16, 2006 12:44 pm
by elecktricity
those are complete lines up there but heres another full line:
1002-66math.random.jpg">1002-66.random.jpg</A> 10-Apr-2006 16:38 12k

Posted: Sun Apr 16, 2006 12:48 pm
by feyd
The tag is cut off on all lines?

Posted: Sun Apr 16, 2006 12:54 pm
by elecktricity
well the first part on it was all the same so I just str_replace it off...

Posted: Sun Apr 16, 2006 12:58 pm
by asgerhallas
if they really look like that, what about:

preg_replace("/\">.*$/", "", $somevar);

Posted: Sun Apr 16, 2006 1:05 pm
by elecktricity
asgerhallas wrote:if they really look like that, what about:

preg_replace("/">.*$/", "", $somevar);
that works if you only put one of them in there but I have like 2000 lines to do..

Posted: Sun Apr 16, 2006 1:13 pm
by feyd

Code: Select all

$data = preg_replace('#(.*?)">\\1</a>.*$#im', '$1', $data);
should work however that is untested.

Posted: Sun Apr 16, 2006 1:13 pm
by asgerhallas
if you have newlines in your file, you can use m [PRCE_MULTILINE] like this:

preg_replace("/\">.*$/m", "", $somevar);

this way, it will treat the $ as "end of line" i stead of "end of string"


EDIT: Damn to slow :)

Posted: Sun Apr 16, 2006 1:22 pm
by elecktricity
thanks for the help all it works great