Jump to content
php.lv forumi

php funkcija


ziedinjsh

Recommended Posts

php funkcija:

function player(){
echo '<div class="song" onclick="snd=new Audio(\'demo/somewhere_is_something_demo.mp3\'); snd.play();"></div>';
}

 

php funkcijas izvade

echo "<div class='play'>".player()."</div>";

 

css:

.play{
padding-left:20px;
border:1px solid #ACD334;
float:left;
margin-right:20px;
}

 

izvadītā funkcija nav iekš paradzētā div, kapēc tā?

Link to comment
Share on other sites

Tāpēc, ka brīdi, kad izsauc funkciju, fukcija izpilda echo, kamēr vietā, kur tu izsauc funkciju, tev vajag, lai funkcija atgriež string-u:

vajag tā:

function player(){
 return '<div class="song" onclick="snd=new Audio(\'demo/somewhere_is_something_demo.mp3\'); snd.play();"></div>';
}

 

Un, lai varētu likt dažādas dziesmas, vajag izmantot funkcijas parametrus:

function player($filename){
 return '<div class="song" onclick="snd=new Audio(\''.$filename.'\'); snd.play();"></div>';
}

Edited by codez
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...