Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:54:51+00:00 2026-06-09T07:54:51+00:00

I am using the Google directions API in my web application, is there any

  • 0

I am using the Google directions API in my web application, is there any way to shorten the direction description provided by Google?

I mean, for example,

Take the 2nd right.
Take the 2nd left toward ...

Can I shorten it? It’s too long.

Can I make it just like this:

2nd right>2nd left>

Is there any way to modify the result? I am using PHP for developing the web application and the JSON format for displaying the API result.
edit:
The API result displays correctly. But I want to remove certain common words such as ‘Take’, ‘The’, ‘at’ etc
API result displaying part of my code:if ($data->status === 'OK') {
$route = $data->routes[0];
foreach ($route->legs as $leg) {
foreach ($leg->steps as $step) {
echo $step->html_instructions . "<br>\n";

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:54:52+00:00Added an answer on June 9, 2026 at 7:54 am

    This worked for me, hopefully it will work for you too…

    <?php
    $test1 = 'Take the 2nd right.';
    $test2 = 'Take the 2nd left toward the exit, then...';
    $reg_find = '/Take the (.*?) (right|left).*/';
    $reg_replace = '$1 $2';
    $results = array(
        preg_replace($reg_find, $reg_replace, $test1),
        preg_replace($reg_find, $reg_replace, $test2)
    );
    echo implode('>', $results);
    ?>
    

    EDIT:

    For a more flexible solution, I have created this:

    <?php
    $test1 = 'Take the 2nd right.';
    $test2 = 'Take the 2nd left toward the exit, then ...';
    $remove = '/( ?)(take|then|at|toward|the|exit|\.|,)( ?)/i';
    $results = array(
        preg_replace($remove, '', $test1),
        preg_replace($remove, '', $test2)
    );
    echo implode('>', $results);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Google Direction API. In this i am http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&mode=driving,OK&sensor=false . When i
can we find area on earth using any web service powered by Google or
I am using the Directions Service of Google Maps V3 API, and I want
I'm builind an application which shows a map with the google api. Using the
I'm using directions for Google Maps V3 API. However I get the javscript error
Hi all I'm using Google Directions API and the data returned from a test
I have an application which is currently using the google map API. I like
I'm making an app for android, I'm using Google Directions API to get and
I am using the Google Directions iOS API. I am getting the data using
I am using javascript, google direction service I have multiple source points on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.