• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

PHP Parameter Application

Hi am researching on doing an application that requires me to execute different commands based on the parameter given... the problem is that the parameters build upon the last..

To start lets take an example of booking a flight to from point A to D. Here is what would happen.

First Parameter: 5
That presents you with options to choose from:
Travelling from:

So you reply with

5*1 to show your travelling from 1

Next prompt is:

Travelling to:

1. A
2. B
3. C
4. D

You reply with 5*1*4 which shows you have chose

Next is When are you travelling...for this you type mmddyyyy
so your next parameter looks


And probably finally,

What is your last name? Which you reply

Some specific details...when you first do the request... i.e parameter 5 alone...you get assigned a unique ID that stays with you till you finish (this part is already working).

So the help i need..... i would like to some general idea on how to;

1. Have the options of A to D come from the DB and ensure the table ID are always valid (that might not be so hard)

2. At the end (when i get thte name), i would like to break this entire parameter into variables in php

$from, $to, $datetravel,$name

This string varies but the * is always separating the different variables...is there any function to tell it make this an array based on * instead of the normal comma separator for arrays.

Any other help how to make this will help!

  • 2
  • 2
1 Solution
explode() can take an argument of separator type...

$param_string = "5*1*4*26102009*LASTNAME" // probably thru $_RQUEST than set but i'll leave that to you...

$parameters = explode("*", $param_string);

echo "id: ".$parameters[0];
echo "to: ".$parameters[1];
echo "from: ".$parameters[2];
echo "date: ".$parameters[3];
echo "lastname: ".$parameters[4];

Ray PaseurCommented:
Hmm.. Is this by any chance a homework assignment?

Note that in your example above, if the "from" point is "A", there is no use in having the "to" point include "A"

Dates in PHP should be interpreted via strtotime(), and then reinterpreted into DATETIME strings in ISO8601 format using date('c') or date('Y-m-d');

Instead of carrying the data fields around in an asterisk-delimited string, a technically competent design would put each field into a table of the data base at the time it was entered.  

It seems like you have a lot of questions here, and so you might benefit from a good beginning primer on the use of PHP and data bases.  This is one of the best, and it is available in PDF format so you can download a copy right away.


Best of luck with your project, ~Ray
bernsoft1Author Commented:
Thanks for your help Briand & Ray.

Its not homework.... Its actually a project for a mobile application service...USSD technology....you know  the ones you type *144*2# to query for information.....

Ray PaseurCommented:
Understood.  Then explode() is the way to take the string apart into component pieces.
bernsoft1Author Commented:
I eventually used explode and switch
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now