Jump to content

Need a simple snippit!


cmj

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.

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.