how would i chop off the last four characters of a string?
12345678
into
1234
Moderator: General Moderators
Code: Select all
<?php
$newstring = substr($oldstring, 0, 4);
?>Code: Select all
<?php
$file_name="image.jpg";
$without_extension = str_replace(".jpg","",$file_name);
?>Code: Select all
<?php
$file_name="image.jpg";
$new_string = str_replace(".jpg","BOB",$file_name);
?>oraknabo wrote:-4 would give you "5678"Code: Select all
<?php $newstring = substr($oldstring, 0, 4); ?>
Whenever I want to find out how to do anything with a string I don't already know, I look here first.
Code: Select all
<?php
$larry = substr($file, 0, -4);
?>Code: Select all
<?php
$without_extension = str_replace(".jpg","",$file_name);
?>Code: Select all
$basename = preg_replace('/\.(jpg|jpeg|gif|png)$/i', '', $filename);Code: Select all
$basename = preg_replace('/\.[^\.]*$/i', '', $filename);Code: Select all
<?php
$basename = preg_replace('/\.[^\.]*$/i', '', $filename);
?>well, you don't actually need the "i" after the slash. i had copied that from the other one, but it's not needed in this one (it makes the search case insensitive by the way).macewan wrote:this will be used definately.
Code: Select all
<?php $basename = preg_replace('/\.[^\.]*$/i', '', $filename); ?>
thanks