phpfan101 Posted December 18, 2009 Share Posted December 18, 2009 I have the following string: "p324u13820" (page 324/user id 13820) The string is in the database, as a mean of tracking what post, came from what user and what page. I want to show a line like this in my logfile: "User id 13820 posted "link" from page page" I have tried a few methods, but I'm in-successful in each attempt, I cant seem to be able to break up the string and set the numbers following "p" in a $page var. to be posted, nor the "u" numbers to a $user var. Anyone? Link to comment https://forums.phpfreaks.com/topic/185645-logging-broken-strings/ Share on other sites More sharing options...
oni-kun Posted December 18, 2009 Share Posted December 18, 2009 You can use a simple function such as this: <?php $str = "p324u13820"; //The string you want separated $split = (explode('u', $str)); $u = $split[1]; $split2 = (explode('p', $split[0])); $p = $split2[1]; echo "User id $u posted (link) from page $p"; //Not sure where you get the link from, you can put there. ?> Returns "User id 13820 posted (link) from page 324" Note this will allow you to have any length user/page string. explode Link to comment https://forums.phpfreaks.com/topic/185645-logging-broken-strings/#findComment-980287 Share on other sites More sharing options...
phpfan101 Posted December 18, 2009 Author Share Posted December 18, 2009 Haha, wow, its that simple? Thanks oni-kun! Link to comment https://forums.phpfreaks.com/topic/185645-logging-broken-strings/#findComment-980301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.