Jump to content

why doesnt it work?


Monkuar

Recommended Posts

function convert_youtube($code,$code1) {
     

        $youtube_count++;

        return '<embed src="http://'.$code.'youtube.com/v/'.$code1.'" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />';
    }
echo $youtube_count;

 

im trying to echo it out, i have like 5 flash videos on the bbcode parser:

 

$RegEx = '%(\[quote(?:=[^\]]*)\].*?)?\[youtube\]http\://(.*?)youtube\.com/watch\?v\=(.*?)\[/youtube\](.*?\[/quote\])?%ie';
if(preg_match_all($RegEx, $text, $matches,PREG_SET_ORDER)){
  foreach($matches as $match){
    if(!empty($match[0]) && empty($match[1]) && empty($match[4])){
      $text = str_replace($match[0], convert_youtube($match[2],$match[3]), $text);
    }else{
  $url = sprintf('http://%syoutube.com/watch?v=%s',$match[2],$match[3]);
      $text = str_replace($match[0], sprintf('%s<a href=\'%s\' target=\"_blank\">%s</a>%s',$match[1],$url,$url,$match[4]), $text);
  
    } 
  }
}

 

if i do "echo "hey";" it works but not any variables.. zzzzzzzzzzzzzzzzz

Link to comment
https://forums.phpfreaks.com/topic/257280-why-doesnt-it-work/
Share on other sites

If you are trying to get the first code to work, then I can tell you why it doesn't work, it's because of variable scope.

http://php.net/manual/en/language.variables.scope.php

You have not declared or initialized the variable within the function's scope, so that ++ won't do anything. It's like you increase something that doesn't exist.

The echo doesn't know of any variable with that name, unless you have declared and initialized it somewhere else, and if you had declared it before a call of the function, the one inside the function wouldn't have found it, unless it was declared global or something, which is bad practice.

 

I recommend you instead increase the variable right after each function call instead.

Link to comment
https://forums.phpfreaks.com/topic/257280-why-doesnt-it-work/#findComment-1318783
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.