填充标题中的URL参数[关闭]

I need help in populating the parameter in the url in the title of the page. What's the best way to do this?

www.mydns.com/sometext1/sometext2

sometext1 | sometext2

Thank you

You want to update the page's title based on the url?

document.title = window.location.pathname.split("/").slice(1).join(" | ");
  1. window.location.pathname gives you {{/sometext1/sometext2}}
  2. split will divide it up
  3. slice(1) will chop off the empty index
  4. join will put it back together

Of if you wanted to achieve this in PHP

<title>My Page<?php echo str_replace('/',' | ',substr($_SERVER['REQUEST_URI'],1)); ?></title>