SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple functions?

    I'm trying to use 2 (mayby more) allmost identical functions on the same page but am having trouble getting the data out of each. Example below:
    PHP Code:
    function get_string_between($string$start$end){
        
    $string " ".$string;
        
    $ini strpos($string,$start);
        if (
    $ini == 0) return "";
        
    $ini += strlen($start);
        
    $len strpos($string,$end,$ini) - $ini;
        return 
    substr($string,$ini,$len);
    }

    function 
    GetData1() {
        
        
    $html '<div>Now this is something!</div><div id="submission">This should be in the output1...</div>';
        
    $parsed get_string_between($html"<div id=\"submission\">""</div>");
        
        
    $returndata[0] = $parsed;
        return 
    $returndata;
    }

    function 
    GetData2() {
        
        
    $html '<div>This is a test</div><div id="content">This should be in the output2...</div><p>Hey hey... </p>';
        
    $parsed get_string_between($html"<div id=\"content\">""</div>");
        
        
    $returndata[0] = $parsed;
        return 
    $returndata;
    }

    $output1 GetData1();
    echo 
    'Output1: '.$output1[0].'<br>';

    $output1 GetData2();
    echo 
    'Output2: '.$output2[0].'<br>'
    What do I do wrong and is it possible?

    Thanks in advance ;-)

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    substr returns a single string, so $returndata[0] = $parsed is wrong.

    It should just be

    return $parsed;

    or

    return get_string_between(......


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •