edit an array
Moderator: General Moderators
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?
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?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
preg_replace('#(?<!/)/.*$#', '', $value);this does not work because it is deleting too much.
for example, my test script, simply outputs "http:"
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
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
<?php
$value = "http://www.google.com/images/hello.html
http://www.google.com/test/test.html";
$value = preg_replace('#(://.*?)?/.*$#m', '\\\\1', $value);
print $value;
?>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
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: