Forum

Thread tagged as: Question

Remove the forward slash?

Hi,

I'm using this to return a parent directory's path

$page_url = perch_page_url(['include-domain' => false,], true);

$lang_slug = dirname($page_url);

print $lang_slug

When I visit this URL site.com/de/demo/test the value of $lang_slug is /de

Is there a way to remove the forward slash? So the value of $lang_slug is just de

I intend to use $lang_slug in another part of my template and I only need the letters, not the forward slash.


Summary information

Perch Runway: 3.1.1, PHP: 7.1.12, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $, with PDO
Server OS: Darwin, cgi-fcgi
Installed apps: content (3.1.1), assets (3.1.1), categories (3.1.1)
App runtimes: <?php $apps_list = [ ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/stephen/Repositories/project/cms/perch
PERCH_CORE: /Users/stephen/Repositories/project/cms/perch/core
PERCH_RESFILEPATH: /Users/stephen/Repositories/project/cms/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
REQUEST_URI: /perch/core/settings/diagnostics/
DOCUMENT_ROOT: /Users/stephen/Repositories/project/cms
HTTP_HOST: project.local
Stephen Meehan

Stephen Meehan 4 points

  • 3 years ago

This works...

$page_url = perch_page_url(['include-domain' => false,], true);
$dir_name = dirname($page_url);
$lang_slug = str_replace('/','', $dir_name);
print $lang_slug;

Visiting this page site.com/de/demo/, the $lang_slug variable is now de