how would I do this?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

how would I do this?

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's a full line from this file look like?
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The tag is cut off on all lines?
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post by elecktricity »

well the first part on it was all the same so I just str_replace it off...
asgerhallas
Forum Commoner
Posts: 80
Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark

Post by asgerhallas »

if they really look like that, what about:

preg_replace("/\">.*$/", "", $somevar);
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post 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..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$data = preg_replace('#(.*?)">\\1</a>.*$#im', '$1', $data);
should work however that is untested.
asgerhallas
Forum Commoner
Posts: 80
Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark

Post 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 :)
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post by elecktricity »

thanks for the help all it works great
Post Reply