Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

remove characters up to specific character

8:48 pm on Feb 8, 2011 (gmt 0)

10+ Year Member

I need to remove all characters up to specific character in a string. I've searched in vain for a answer, so I hope you can help me.

It's to build a index/sitemap automatically

I have code that looks through specific directory's and outputs a list of contents:-

<li><a href="http://'path/to'.$filename.'">'.ucfirst($menuitem).'</a></li>

$filename = name_of_file.htm
$menuitem = name_of_file [.htm and '_' stripped]

My problem is the site is in two languages so ideally I'd like:-

<li><a href="http://'path/to'.$filename.'">'.ucfirst($menuitem).'<br />'.ucfirst($second_menuitem).'</a></li>

$filename = 'English_name~Spanish_name.htm'
$menuitem = 'English_name'
$second_menuitem = 'Spanish_name'

I've worked out how to strip everything after a the "~", but can't fathom how to strip everything before the "~"

Any help would be much appreciated.
5:47 am on Feb 10, 2011 (gmt 0)

5+ Year Member

list($one,$two) = split('~',$filename);

$menu_one = $one;
$menu_two = str_replace('.html','',$two);

Not sure if its what your after, but the above will pass 'English_name' to $menu_one and 'Spanish_name' to $menu_two