Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Friday, November 4, 2022

PHP code for String Tokenize

 PHP code for String Tokenize


<?php
$string = "Hello Kamal. How are you Doing?";
$token = strtok($string, " ");

while ($token !== false)
{
echo "$token<br>";
$token = strtok(" ");
}
?>

Wednesday, September 14, 2022

How to remove extension from string in PHP

 

How to remove extension from string in PHP


There are multiple ways to remove extension from a file name in PHP
 
<?php
  
// Initializing a variable with filename
$file = 'myfilename.jpg';
  
// Extracting only filename using constants
$fileWithoutExt = pathinfo($file, PATHINFO_FILENAME);
  
// Printing the result
echo $fileWithoutExt;
  
?>



Output

filename