Jump to content

Recommended Posts

Hi Guys,

 

Here is the scope. I am writing a mobility system for the visually impaired that will store information about how to get from one place to another in several steps. The number of steps changes depending on where the route goes. I've stored these into a database. The 2 columns we are interested in are "steps" which contains the number of steps in the route, and "description" which is the textual description of the steps to take, where a step is defined as a section of the route. In the description field, the data is stored seperated by a comma. For example,

 

Step 1 - Go here, then turn left, Step 2 - Then go straight, Step 3 - Your now there.

 

Since we know the number of steps is 3, the steps column in the databsse will contain 3. What we do not know is the number of commas and where to split.

 

What I want to do is to be able to split at the commas and store these in variables so I can format them into an ordered list.

 

Is there a way to loop through this and split at the commas and also the dashes without messing up the order of everything and then being able to make everything into bullet points even if there are 20 steps or 100 steps?

 

Thanks for your help.

 

James Grunshaw.

You should seperate your steps with a different character, such as |*| Your steps will be like so

 

tep 1 - Go here, then turn left|*|Step 2 - Then go straight|*|Step 3 - Your now there

 

This allow you to split your steps in to an array easily

$steps = explode('|*|', $row['steps']);

echo 'Steps to take: <ul>';

foreach($steps as $step)
{
    echo '<li>' . $step . '</li>';
}

echo '</ul>';

Excellant, thats working a bit better for what I wanted. I just have one more thing.

 

Is it possible to split at the comma aswell so in affect you would have say a nested list?

 

Step 1

      Go here

      Then here

Step 2

    Then do this

    Then that

Step 3

    Finish

 

Thanks again.

 

PS > I'm Visually Impaired, having a very difficult time with these CAPATCHAS - are they really neccesary on an already authenticated and registered system?

Excellant, thats working a bit better for what I wanted. I just have one more thing.

 

Is it possible to split at the comma aswell so in affect you would have say a nested list?

 

<?php

$row['steps'] = 'Step 1 - Go here, then turn left|*|Step 2 - Then go straight, turn right at next road|*|Step 3 - Your now there';

$route_steps = explode('|*|', $row['steps']);

echo "Steps to take:
<ul>\n";

foreach($route_steps as $steps)
{
    list($step_num, $steps) = explode(' - ', $steps);

    $sub_steps = explode(', ', $steps);

    echo '  <li>' . $step_num . '
    <ul>
      <li>' . implode("</li>\n      <li>", $sub_steps) . '</li>
    </ul>
  </li>'."\n";
}

echo '</ul>';

?>

 

PS > I'm Visually Impaired, having a very difficult time with these CAPATCHAS - are they really neccesary on an already authenticated and registered system?

As you have less than 10 posts you are required to full in the Captcha. Once you have reached 10 posts or more it will not display.

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.