Title: url encoding
Last modified: August 21, 2016

---

# url encoding

 *  Resolved [2020media](https://wordpress.org/support/users/2020media/)
 * (@2020media)
 * [13 years ago](https://wordpress.org/support/topic/url-encoding-1/)
 * I have a rather complete url that returns a csv like structure.
 * in it’s basic form its fine
    [http://countdown.api.tfl.gov.uk/interfaces/ura/instant_V1?StopCode1=52762](http://countdown.api.tfl.gov.uk/interfaces/ura/instant_V1?StopCode1=52762)
 * but in a more complex example, it does not work
 * [http://countdown.api.tfl.gov.uk/interfaces/ura/instant_V1?StopCode1=52762&ReturnList=LineName,DestinationText,EstimatedTime](http://countdown.api.tfl.gov.uk/interfaces/ura/instant_V1?StopCode1=52762&ReturnList=LineName,DestinationText,EstimatedTime)
 * Is it feasible to add urlencoding (if that’s the right term) to get your script
   to blindly accept the url as a csv?
    Or is this straying too far from the purpose
   of this plugin do you think?
 * [http://wordpress.org/extend/plugins/csv-to-sorttable/](http://wordpress.org/extend/plugins/csv-to-sorttable/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [13 years ago](https://wordpress.org/support/topic/url-encoding-1/#post-3851489)
 * I’ll have to look into this a bit closer, but at first glance I think part of
   the problem is that your URL results in three columns in the first row, but four
   columns in every other row.
 *  Plugin Author [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [13 years ago](https://wordpress.org/support/topic/url-encoding-1/#post-3851494)
 * Using the URL you provided above, I’m getting this in the table data array:
 *     ```
       array (size=3)
         0 =>
           array (size=3)
             0 => string '[4' (length=2)
             1 => string '1.0' (length=3)
             2 => string '1371517737617]' (length=14)
         1 =>
           array (size=4)
             0 => string '[1' (length=2)
             1 => string 'Bullen Street' (length=13)
             2 => string 'N44' (length=3)
             3 => string '1371518096000]' (length=14)
         2 =>
           array (size=4)
             0 => string '[1' (length=2)
             1 => string 'Bullen Street' (length=13)
             2 => string '344' (length=3)
             3 => string '1371519166000]' (length=14)
       ```
   
 * Not sure if that is the expected result, but if it is you can always clean it
   up using the `csv_to_sorttable_data_array` filter.
 *  Thread Starter [2020media](https://wordpress.org/support/users/2020media/)
 * (@2020media)
 * [13 years ago](https://wordpress.org/support/topic/url-encoding-1/#post-3851529)
 * Hi
 * The first url I gave does indeed produc those results but I am using your filter
   to discard the first row to cope with the poor data.
 * However it is the second url I am posting about. If you just click this url you’ll
   see it produces a csv-like structure pretty much idenditcal to the first url.
   
   However the url itself is more complex, and I think this is the problem. Possibly
   the commas are confusing it.
 * My first thought was about using rawurlencode or urlencode to make sure WordPress
   does not get confused.
 *  Plugin Author [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [13 years ago](https://wordpress.org/support/topic/url-encoding-1/#post-3851594)
 * Yeah, sorry but this is a bit beyond the scope of the support I can provide.
 * I can tell you that the plugin uses [wp_remote_fopen()](http://codex.wordpress.org/Function_Reference/wp_remote_fopen)
   to open the source file…hopefully that will get you pointed in the right direction.
 * If you find a solution, please post it here and I will be sure to document it.
 *  Plugin Author [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [13 years ago](https://wordpress.org/support/topic/url-encoding-1/#post-3851633)
 * Marking this thread as resolved. If you are able to modify the plugin to support
   this feature and would like to contribute to this open source project, please
   submit a pull request at: [https://github.com/sscovil/csv-to-sorttable](https://github.com/sscovil/csv-to-sorttable)
 *  Thread Starter [2020media](https://wordpress.org/support/users/2020media/)
 * (@2020media)
 * [13 years ago](https://wordpress.org/support/topic/url-encoding-1/#post-3851640)
 * Hi
    Yes I agree it’s pushing the support a bit.
 * I have got it working by changing a line in the plugin (complete bodge) to hardcode
   the url I want.
 *  // Get contents of .CSV file as string.
    // $file = wp_remote_fopen( $src );
   $file = wp_remote_fopen(“my_long_complex_url”);
 * for my purposes this does the job!
 *  Plugin Author [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [13 years ago](https://wordpress.org/support/topic/url-encoding-1/#post-3851642)
 * Ah, interesting. So it’s probably the shortcode attribute parser that is mucking
   things up.
 * In that case, you could use something like this in your theme `functions.php`
   instead of modifying the plugin:
 *     ```
       if ( class_exists( 'CSV_to_SortTable' ) ) {
           /**
            * Custom CSV Shortcode
            *
            * Use shortcode [customcsv] with all the same attributes as [csv] except 'src', which is hard-coded.
            *
            * @uses function shortcode_atts
            * @uses function wp_remote_fopen
            *
            * @param  array  $atts User-defined shortcode attributes.
            * @return string       HTML for rendered table, or blank string if no data.
            */
           function custom_csv_shortcode( $atts ) {
               $plugin = CSV_to_SortTable::instance();
   
               // Default values for shortcode attributes.
               $defaults = array(
                   'unsortable' => '',     // Comma-separated list of column numbers that should be unsortable.
                   'number'     => '',     // Comma-separated list of column numbers that should be sorted as numeric.
                   'date'       => '',     // Comma-separated list of column numbers that should be sorted as date.
                   'group'      => 0,      // Column to check for identical values and apply matching class to rows.
                   'disable'    => '',     // Available options: css, icons, images, all
               );
               $atts = shortcode_atts( $defaults, $atts );
   
               // Create an array of enabled features based on 'disable' attribute.
               $enabled = $plugin->enabled_features( $atts['disable'] );
   
               // Enqueue plugin JavaScript & CSS only on pages where shortcode is used.
               $plugin->load_js_css( $enabled );
   
               // Use hard-coded CSV file source.
               $src = 'http://countdown.api.tfl.gov.uk/interfaces/ura/instant_V1?StopCode1=52762&ReturnList=LineName,DestinationText,EstimatedTime';
   
               // Get contents of .CSV file as string.
               $file = wp_remote_fopen( $src );
   
               // Parse CSV string into a multidimensional array.
               $rows = $plugin->parse_csv( $file );
   
               // Render table and return HTML string.
               return $plugin->render_table( $rows, $atts );
           }
           add_shortcode( 'customcsv', 'custom_csv_shortcode' );
       }
       ```
   
 *  Thread Starter [2020media](https://wordpress.org/support/users/2020media/)
 * (@2020media)
 * [13 years ago](https://wordpress.org/support/topic/url-encoding-1/#post-3851643)
 * That’s a nice solution, I’ll give it a go.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘url encoding’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/csv-to-sorttable_d4e1eb.svg)
 * [CSV to SortTable](https://wordpress.org/plugins/csv-to-sorttable/)
 * [Support Threads](https://wordpress.org/support/plugin/csv-to-sorttable/)
 * [Active Topics](https://wordpress.org/support/plugin/csv-to-sorttable/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/csv-to-sorttable/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/csv-to-sorttable/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [2020media](https://wordpress.org/support/users/2020media/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/url-encoding-1/#post-3851643)
 * Status: resolved