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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.