Issue
I am not familiar with preg_replace function of php. I need to solve an issue by using this function.
My string is sidebarCond/none.php. I need to remove folder name whatever it is (like: sidebarCond/ or folder-name/) and also the extension (Like: .php or .html).
$sidebar = 'sidebarCond/none.php';
$sidebar = str_replace( 'sidebarCond/', '', $sidebar );
$sidebar = str_replace( '.php', '', $sidebar );
This is the code of how I solve my problem, but this is not a smart solution.
Solution
Don't use string functions in this case. Use pathinfo
$sidebar = 'sidebarCond/none.php';
$sidebar = pathinfo($sidebar)['filename'];
OR
$sidebar = 'sidebarCond/none.php';
$sidebar = pathinfo($sidebar, PATHINFO_FILENAME);
Answered By - ksiger Answer Checked By - David Goodson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.