urtlking2jo Posted January 18, 2007 Share Posted January 18, 2007 I am trying to figure out the easiest way to change a string with a concatenated suffix back to the original string.I add the suffix "_mil" to all account names created from a particular log in form. For query/storage purposes, I want that suffix included (example: name_mil), but for display purposes, I only want the original user name (example: name). I only display it in one place, so I don't want to pass it as a session variable to every page.Can anyone help me with the code it would take to "shorten" the user names back to what the user "thinks" their user name is? Thanks! Link to comment https://forums.phpfreaks.com/topic/34665-string-manipulation/ Share on other sites More sharing options...
Caesar Posted January 18, 2007 Share Posted January 18, 2007 I suppose one easy way would be...[code]<?php $string = 'name_mil'; $array = explode("_",$string); $name = $array[0];?>[/code] Link to comment https://forums.phpfreaks.com/topic/34665-string-manipulation/#findComment-163355 Share on other sites More sharing options...
utexas_pjm Posted January 18, 2007 Share Posted January 18, 2007 Try this:[code]<?php define('SUFFIX', '_mil'); $username = 'foo' . SUFFIX; $newStr = substr($username, 0, strlen($username) - strlen(SUFFIX));?>[/code]Best,Patrick Link to comment https://forums.phpfreaks.com/topic/34665-string-manipulation/#findComment-163358 Share on other sites More sharing options...
urtlking2jo Posted January 18, 2007 Author Share Posted January 18, 2007 Thanks! Either way should work! Link to comment https://forums.phpfreaks.com/topic/34665-string-manipulation/#findComment-163360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.