How to separate string into parts in PHP -


right have:

$path2 = $file_list1;  $dir_handle2 = @opendir($path2) or die("unable open $path2");  while ($file2 = readdir($dir_handle2)) {  if($file2 == "." || $file2 == ".." || $file2 == "index.php" )  continue;  echo ''.$file2.'<br />';  }  closedir($dir_handle2); echo '<br />'; 

when $file2 returned, last 4 characters in string end in number plus file extension .txt, this:

file_name_here1.txt some_other-file10.txt 

so question is, how can separate $file2 returns string in 2 parts, $file_name , $call_number this?:

echo 'file: '.$file_name.' call: '.call_number.'<br />'; 

returns:

file: file_name_here call: 1 file: some_other-file call: 10 

instead of this:

echo ''.$file2.'<br />'; 

returns:

file_name_here1.txt some_other-file10.txt 

thanks....

i'm big advocate of regex decided go different here. check out:

$file = 'file_name_here19.txt'; $file_parts = pathinfo($file); $name = $file_parts['filename']; $call = ''; $char = substr($name, strlen($name) - 1); while(ord($char) >= 48 && ord($char) <= 57) {     $call = $char . $call;     $name = substr($name, 0, strlen($name) - 1);     $char = substr($name, strlen($name) - 1); } echo 'name: ' . $name . ' call: ' . $call; 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -