How to parse multiple links from one variable?

So I have a Pod set up as a shortcode where it outputs the links for files a user uploads. Here is the following shortcode I made (imagine my shortcode being [getShortCode field="upload_files"]:

function pods_current_user($atts) {
   extract(shortcode_atts(array(
      'currUser' = get_current_user_id(),
   ), $atts)); 
   extract(shortcode_atts(array(
    'field' = "display_name",
 ), $atts)); 
    $message = do_shortcode('[pods name="user" where="ID = '.$currUser.'"] {@'.$field.'}[/pods]');
    return $message;
 }
add_shortcode('getShortCode', 'pods_current_user'); 

At the moment what it outputs is a set of links to the uploaded files, but as a plain text, not hyperlinked. Something like the following:

http://secureservercdn.net/196.71.233.106/7ho.fa0.myftpupload.com/wp-content/uploads/2019/11/Screnshot-5.png?time=1575937207 http://secureservercdn.net/196.71.233.106/7ho.fa0.myftpupload.com/wp-content/uploads/2069/11/Geting-started-with-OneDrive-1.pdf?time=1675037207

(without the hyperlinks). Is there a way to be able to separate the links from my one variable into a scalable array, right in the function for my shortcode? Like maybe detect where the http is and separate the links like that? Thanks.

Topic pods-framework php Wordpress

Category Web


I would look into this question here https://stackoverflow.com/questions/36564293/extract-urls-from-a-string-using-php

You could use the above link detection to do something like this in your shortcode:

<?php
function pods_current_user($atts) {
   extract(shortcode_atts(array(
      'currUser' => get_current_user_id(),
   ), $atts)); 
   extract(shortcode_atts(array(
    'field' => "display_name",
 ), $atts)); 


    $message = do_shortcode('[pods name="user" where="ID = '.$currUser.'"] {@'.$field.'}[/pods]');

    preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $message, $match);

    // Do something with your links via the $match array.

    return $message;
 }
add_shortcode('getShortCode', 'pods_current_user'); 

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.