Jump to content

logging broken strings


phpfan101

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.