Jump to content

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 />';
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.