Jump to content

[SOLVED] Removing text from a given value.


MrXander

Recommended Posts

Hi there,

 

What I need to do is display the last 8 values from a database on my site, which is fine, but the question is, I want to remove the first part of the data.

Basically, the thing I need to display is a URL, for example, <b>http://domain.com/</b>2596. I need to be able to remove the "http://domain.com/" from showing on the main page, and only keep the numbers afterwards.

Is there a way to do this?

Link to comment
https://forums.phpfreaks.com/topic/75406-solved-removing-text-from-a-given-value/
Share on other sites

You could explode by the forward slash, and select the last element of the array:

 

<?php
$sql = "SELECT `url` FROM `yourtable` LIMIT 8";//obviously you'll want an order by statement in there, but im not sure how you're defining last 8
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc()){
$bits = explode('/',$row['url']);
$num = $bits[count($bits)-1];//get the last part of the array
echo $num.'<br />';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.