Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Regex help

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #30598
    marcdefiant
    Participant

    Hey guys, I have a little script where you input a shortcode and it will return a link..

    shortcode:
    [link:CSS Tricks|https://css-tricks.com]
    or
    [link:CSS Tricks|https://css-tricks.com|Link to CSS Tricks]

    and it will output:
    <a href=”https://css-tricks.com”>Css Tricks</a>
    and
    <a href=”https://css-tricks.com&#8221; title=”Link to CSS Tricks”>Css Tricks</a>

    I’m using preg_replace, but I have to use an array to deal with both cases:

    function linx($i){
    $a = array(
    "/[link:(.*)|(.*)|(.*)]/",
    "/[link:(.*)|(.*)]/"
    );
    $x = array(
    "$1",
    "$1"
    );
    return preg_replace($a, $x, $i);
    }

    I’ve tried and tried to have only one regex code to deal with both cases, with and without the title for the anchor..

    How can i achieve this?

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.