• Sam

    (@ssharples)


    here’s my shortcode:

    [willhill_text_link xmlurl=”http://cachepricefeeds.williamhill.com/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=313&marketSort=–&filterBIR=N”%5D

    here’s my function:

    function willhill_text($atts) {
       extract(shortcode_atts(array(
          'xmlurl' => '',
       ), $atts));
    $rss = simplexml_load_file($xmlurl);
    print_r($rss);
    }
    
    add_shortcode('willhill_text_link', 'willhill_text');

    If you run it, you will see an xml feed outputted. But, if you simply do this:

    $rss = simplexml_load_file('http://cachepricefeeds.williamhill.com/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=313&marketSort=--&filterBIR=N');
    print_r($rss);

    You get a different output.

    It is as if the function is ignoring everything from ‘?action’ onwards from the url being passed.

    Can anybody explain why?

    Thanks

Viewing 1 replies (of 1 total)
  • Hi Sam,

    You have to add line $str_format = str_replace(array(" & # 0 3 8 ;"," & a m p ;"), "&", $xmlurl); into your function to fix this.

    Updated function :

    function willhill_text($atts) {
    	extract( shortcode_atts( array(
    		"xmlurl"=>'http://'),
    		$atts
    		)
     	);
    
            // Remove spaces from " & # 0 3 8 ;"," & a m p ;"
     	$str_format = str_replace(array(" & # 0 3 8 ;"," & a m p ;"), "&", $xmlurl);
    
     	$rss = simplexml_load_file(esc_url_raw($str_format));
     	print_r($rss);
    }
    add_shortcode('willhill_text_link', 'willhill_text');

    Pastie.org URL : http://pastie.org/private/hjtfgnqsbzfanfdhumemw

    I hope this helps.

    ~ Dipak G.

Viewing 1 replies (of 1 total)
  • The topic ‘basic passing url through shortcode causing unusual problem’ is closed to new replies.