Breaking News
Loading...

How to get text between two characters in php

Share on Google Plus

How to get text between two characters in php

<?php 
$input = "[modid=256]";
preg_match('~=(.*?)]~', $input, $output);//here the value is fixed between = and ]
echo $output[1]; // the output will be 256
?>

 ..

preg_match is a function to find the string values in php .. as same as substring
I hope this will help you :)

<?php 
$myurl = "my/folders/go/here/index.php"; 

$file = basename($myurl); 

$parts = explode(".", $file); 

//File name 
echo $parts[0]; 

//File format 
echo $parts[1]; 

?>

OUTPUT : indexphp

You Might Also Like

0 comments

About me


Like us on Facebook