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 8893207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:11:18+00:00 2026-06-14T23:11:18+00:00

I want create my own shortcode In the text i can put the shortcode

  • 0

I want create my own shortcode

In the text i can put the shortcode for example :

The people are very nice , [gal~route~100~100] , the people are very
nice , [ga2l~route2~150~150]

In this expression you can see the shortcodes into [ ] tags , i want show the text without this shortcodes and replace it for gallery ( with php include and read the path gallery from shortcode)

I think use this method , as you can see down , but none of them works for me , however people here can tell me something or give me any idea which can help me

 <?php
 $art_sh_exp=explode("][",html_entity_decode($articulos[descripcion],ENT_QUOTES));

 for ($i=0;$i<count($art_sh_exp);$i++) {

 $a=array("[","]"); $b=array("","");

 $exp=explode("~",str_replace ($a,$b,$art_sh_exp[$i]));


 for ($x=0;$x<count($exp);$x++) { print
 "".$exp[1]."-".$exp[2]."-".$exp[3]."-<br>"; }

 } ?>

Thanks

  • 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-14T23:11:19+00:00Added an answer on June 14, 2026 at 11:11 pm

    I suggest you use a regular expression to find all occurrences of your shortcode pattern.

    It uses preg_match_all (documentation here) to find all the occurrences and then simple str_replace (documentation here) to put the transformed shortcode back in the string

    The regular expression contained in this code simply tries to match 0 to unlimited occurences of a character between brackets [ and ]

    $string = "The people are very nice , [gal~route~100~100] , the people are very nice , [ga2l~route2~150~150]";
    $regex = "/\[(.*?)\]/";
    preg_match_all($regex, $string, $matches);
    
    for($i = 0; $i < count($matches[1]); $i++)
    {
        $match = $matches[1][$i];
        $array = explode('~', $match);
        $newValue = $array[0] . " - " . $array[1] . " - " . $array[2] . " - " . $array[3];
        $string = str_replace($matches[0][$i], $newValue, $string);
    }
    

    The resulting string is now

    The people are very nice , gal - route - 100 - 100 , the people are very nice , ga2l - route2 - 150 - 150
    

    By breaking the problem in 2 phases

    • Finding all occurrences
    • Replacing them with new values

    It is simpler to develop and debug. It also makes it easier if you want to change at one point how your shortcodes translate to URLs or whatever.

    Edit: as suggested by Jack, using preg_replace_callback would allow to do that simpler. See his answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create my own PHP web app where people can signin with
I want to create my own SeekBar because I can't find anything like with
I want to create an website where users can create their own teaching resources,
I want to create own widget that will be able to interpret the text
I want to create my own incremental backup solution using C#. How can I
i want to create my own custom admin-url in wordpress... how can i do?
I want to create an own charting control, which can be embedded and used
since I can not markup content inside tags I want to create my own
I want to create own filetype to save objects in my app. Basically, I
I want to create my own class named Point, but am running into issues

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.