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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.