Προς το περιεχόμενο

php echo problem


varathro

Προτεινόμενες αναρτήσεις

an px:

 

>
<?php

function foobar ($value)
{
   echo $value;
}

?>

 

gia na emfaniseis to keimeno pou tha baleis sthn function prepei na thn kaleseis ki' olas...

 

opote..

 

>
<?php
foobar ("Php is powerfull");
?>

 

episeis kapoies functions den kanoun echo (analoga pos tis orisame, an tha kanoun echo h return) kai mporei na einai kapos etsi:

 

>
<?php

function foobar ($value)
{
   return ($value);
}

?>

 

tote gia na bgaleis to apotelesma prepei na kaneis:

 

>
<?php
echo foobar ("Php is powerfull");
?>

 

EDIT:

Episeis mia metablhth h opoia einai ekso apo thn function den mporeis na thn kaleseis mesa apo thn function kai antistrofa

 

px to parakato den bgazei tipota sthn othonh:

 

>
<?php

$variable = 'PHP is powerfull';

function foobar ()
{
echo $variable;
}

foobar();

?>

 

gia na kaleseis mia metablhth mesa se mia function h opoia einai dhlomenh ekso apo ayth tote prepei na thn kaneis global px:

>
<?php

$variable = 'PHP is powerfull';

function foobar ()
{
global $variable;

echo $variable;
}

foobar();

?>

 

kai kati teleytaio asxeto me ayto pou zhtas, to parakato mporei na sou fanei xrishmo ;)

 

des to apotelesma pou exei ayto:

>
<?php

$variable = 1;

function foobar ($variable)
{
echo ++$variable;
}

foobar($variable);
echo "<br />".$variable;

?>

 

kai sigkrineto me to apotelesma pou exei ayto:

>
<?php

$variable = 1;

function foobar (&$variable)
{
echo ++$variable;
}

foobar($variable);
echo "<br />".$variable;

?>

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

OX! kako synithio na mhn diabazeis olh thn erothsh :roll:

 

ayto poy thes esy einai ayto:

 

example.php

>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php

function foobar ($value)
{
echo $value;
}

?>
</head>

<body>
<div><?= foobar("Foobar"); ?></div>
</body>
</html>

 

PS: perito na po pos h selida prepei na einai .php kai oxi .html

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

auth einai.

 

><?php
function readwritetofile (){
       	$myFile = "test.txt";
	$fh = fopen($myFile, 'r') or die("can't open file");
       	$var = fread($fh, filesize($myFile));
       	$var =$var +1;
       	echo $var;
       	fclose($fh);
       	$fh1 = fopen($myFile, 'w') or die("can't open file");
       	fwrite($fh1, $var);
	fclose($fh1);
}
 ?>

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

basika otan se mia php selida eixa mono ayta xwris na einai se function, douleue mia xara, otan thn fortona ston browser.

>       
<?
$myFile = "test.txt";
       $fh = fopen($myFile, 'r') or die("can't open file");
           $var = fread($fh, filesize($myFile));
           $var =$var +1;
           echo $var;
           fclose($fh);
           $fh1 = fopen($myFile, 'w') or die("can't open file");
           fwrite($fh1, $var);
       fclose($fh1);
 ?>

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

otan xreisimopoio function den emfanizei thn var otan fortonei h php selida pou exei thn function me tis entoles.

 

otan bgalw th function kai afhsw mono tis entoles kai bgalw kai to php apo to <?php sthn arxh mou emfanizei thn var.

 

mporeis na mou ekseighseis giati symvainei ayto;

 

A empneysh......

mhpws den mou emfanizei tipota giati aplws toy lew fortose thn php selida me thn function kai oxi xrhsimopoihse thn function....

an einai etsi to prepei na thn kalesw. tha to testarw kai tha doume.

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...