dongzhou5344 2015-07-02 12:14
浏览 56

将codeigniter数据传递给简单的html dom url变量

I have a problem. I would like to pass my Codeigniter Mysql variables (which I can use at the template as {{ category:country }} using this library http://simplehtmldom.sourceforge.net/ ) at a simple HTML-DOM URL variable. I tried lot of variation without result.

Here is the beginning of my code:

<?php

include_once('simple_html_dom.php');

ini_set('display_errors', true);
error_reporting(E_ALL);


$url = 'http://address.com/".{{ category:country }}."/'; 

?>

I would like to open the address, like if I got the germany variable, then parse this: http://address.com/germany .

Many thanks!

  • 写回答

2条回答 默认 最新

  • dqstti8945 2015-07-02 14:08
    关注

    If I understand the issue correctly then what you want might be tricky or impossible.

    Basically, Simply HTML DOM is working with code in memory so when you feed it $url then it is trying to visit a URL named http://address.com/".{{ category:country }}."/

    The template parser acts upon PHP's output buffer so it's not invoked until it is ready to call all the ob_* functions

    If your templating engine supports it then you will need to do something like this:

    <?php
    
    include_once('simple_html_dom.php');
    
    ini_set('display_errors', true);
    error_reporting(E_ALL);
    
    $url = 'http://address.com/".{{ category:country }}."/'; 
    
    // Find a function which will parse the string you have passed into it
    $url = FAKE_FUNCTION_templating_engine_PARSE_NOW($url);
    
    // At this point, Simple HTML DOM will be able to properly use the $url
    
    ?>
    
    评论

报告相同问题?