edit an array

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

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it does actually require some matching to protect it from fiddling...
videogame
Forum Newbie
Posts: 11
Joined: Wed Jan 05, 2005 8:41 pm

Post by videogame »

lets say the link says http://www.website.com/index.html

the script identifies that it ends in .html

how can i make it so that it deletes whatever is between the / and the .html so that only http://www.website.com is left?
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

preg_replace('#(?<!/)/.*$#', '', $value);
videogame
Forum Newbie
Posts: 11
Joined: Wed Jan 05, 2005 8:41 pm

Post by videogame »

this does not work because it is deleting too much.

for example, my test script, simply outputs "http:"

Code: Select all

<?php
$value = "http://www.google.com/images/hello.html";
$value = preg_replace('#(?<!/)/.*$#', '', $value);
print $value
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

as I said, untested.
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

&lt;?php
	$value = "http://www.google.com/images/hello.html
http://www.google.com/test/test.html";
	$value = preg_replace('#(://.*?)?/.*$#m', '\\\\1', $value);
	print $value;
?&gt;
videogame
Forum Newbie
Posts: 11
Joined: Wed Jan 05, 2005 8:41 pm

Post by videogame »

this outputs http://www.google.com but i would like it to output http://www.google.com/images/ instead... so simply take out the hello.html
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try to figure it out. We're not here to do all the work for you.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

As feyd said give it a try, post some more code, and well point out your mistakes and how you can improve your code
Post Reply