Jump to content
php.lv forumi

apgraizī stringu


jam

Recommended Posts

$str = '/fol1/fol2/fol3/ ';
$sagr = explode('/', $str);
print_r($sagr);
/*
echo $sagr[0]; //shis buus pirmais
echo $sagr[1]; //shis buus otrais
*/

 

viens no variantiem , un tad skaties ko tew waig

Link to comment
Share on other sites

Ir varianti:

<?php
 $str = '/fol1/fol2/fol3/';

#1 variants
 echo implode('/', array_splice(explode('/', $str), 0, -2)).'/';

#2 variants
 if (preg_match('@^(.*/)[^/]+/$@', $str, $m)) {
   echo $m[1];
 }

#3 variants
 echo substr($str, 0, strrpos(substr($str, 0, -1), '/')+1);

?>

Edited by bubu
Link to comment
Share on other sites

×
×
  • Create New...