Jump to content

Recommended Posts

Hey guys, i'm a forum dude myself, and realize that what I am doing is completely newbish, selfish, and on some levels...

 

I'm not a PHP guy, but I just need a SIMPLE script.

 

All I am doing is passing three strings through URI.. Example.

 

I'll send a url that looks like this, to the script:

 

/code.php?Good%20Afternoon%20CMJ  I need to split the three 'variables' at the ascii space so I can utilize JUST the name (or third variable).

Link to comment
https://forums.phpfreaks.com/topic/145783-need-a-simple-snippit/
Share on other sites

Is there supposed to be a variable assigned to this URL?

 

For example:  /code.php?message=Good%20Afternoon%20CMJ

 

Anyway, however you grab this string you have to decode it, explode it (as premiso mentioned) and assign a variable to the last piece of the array (assuming the last piece is going to always be the one you need).

 

With a little tweaking, it should look something like:

 

$string = urldecode("Good%20Afternoon%20CMJ");
$pieces = explode(" ", $string);
foeach($pieces as $key => $value) {
   echo "key => " . $key . " value => " . $value;
   $name = $value;
}
?>

 

 

 

 

Is there supposed to be a variable assigned to this URL?

 

For example:  /code.php?message=Good%20Afternoon%20CMJ

 

Anyway, however you grab this string you have to decode it, explode it (as premiso mentioned) and assign a variable to the last piece of the array (assuming the last piece is going to always be the one you need).

 

With a little tweaking, it should look something like:

 

<?php
$string = urldecode("Good%20Afternoon%20CMJ");
$pieces = explode(" ", $string);
foeach($pieces as $key => $value) {
   echo "key => " . $key . " value => " . $value;
   $name = $value;
}
?>

 

Why use a for each? He knows he wants, the third var.

 

$string = urldecode("Good%20Afternoon%20CMJ");
list($v1,$v2,$v3) = explode(" ", $string);

echo $v3;

Why use a for each? He knows he wants, the third var.

 

$string = urldecode("Good%20Afternoon%20CMJ");
list($v1,$v2,$v3) = explode(" ", $string);

echo $v3;

 

Sorry, I had to do this :)

 

Why use a list why not just do this:

$string = urldecode("Good%20Afternoon%20CMJ");
$var = explode(" ", $string);
$var = $var[2];
echo $var;

 

:) Since he only needs the 3rd one anyways.

 

Why use a for each? He knows he wants, the third var.

 

$string = urldecode("Good%20Afternoon%20CMJ");
list($v1,$v2,$v3) = explode(" ", $string);

echo $v3;

 

Sorry, I had to do this :)

 

Why use a list why not just do this:

$string = urldecode("Good%20Afternoon%20CMJ");
$var = explode(" ", $string);
$var = $var[2];
echo $var;

 

:) Since he only needs the 3rd one anyways.

 

 

haha yeah I should have used that. list should be depreciated.

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.