TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Tips & Tricks (http://www.talkphp.com/tips-tricks/)
-   -   Outputting data without print/echo (http://www.talkphp.com/tips-tricks/2386-outputting-data-without-print-echo.html)

TlcAndres 03-01-2008 06:39 PM

Outputting data without echo/print
 
Well I'd like to see how inventive you all are in outputting data to the screen without using echo or print or C hooks (Alan)


Here goes my try

PHP Code:


function newecho($text)
{
     
$path $_SERVER['DOCUMENT_ROOT'] . '/file.html';
     
file_put_contents($path,$text);
     include_once(
$path);



Alan @ CIT 03-01-2008 08:13 PM

Can't beat good ol' streams :-)

PHP Code:

function newecho($text)
{
    
$output fopen('php://output''w');
    
fputs($output$text);


Alan

ReSpawN 03-01-2008 10:05 PM

It might be kinda lame but there is always var_dump();.
PHP Code:

$myVar 'TalkPHP';
var_dump($myVar); 


Wildhoney 03-01-2008 10:15 PM

If we're going to be lame then there's printf, too!

php Code:
printf('%s', 'TalkPHP');

Long live the geniuses.

ReSpawN 03-01-2008 10:17 PM

Quote:

Originally Posted by Wildhoney (Post 11788)
If we're going to be lame then there's printf, too!

php Code:
printf('%s', 'TalkPHP');

Long live the geniuses.

Damn it, you beat me to it.
PHP Code:

$name 'TalkPHP';
$threads 1365;
$posts 10486;
$members 1892;

$myString "%1\$s current stats: Threads: %2\$s, Posts: %3\$s, Members: %4\$s";

printf($myString$name$threads$posts$members); 


Salathe 03-01-2008 11:58 PM

PHP Code:

Hello World


ReSpawN 03-02-2008 07:46 PM

Quote:

Originally Posted by Salathe (Post 11800)
PHP Code:

Hello World


...? I don't get it?

StevenF 03-02-2008 08:13 PM

Quote:

Originally Posted by ReSpawN (Post 11843)
...? I don't get it?

He didn't say using only PHP. I guess that what Salathe was getting at.

Salathe 03-02-2008 11:18 PM

It outputs data without using print/echo. Put it in a .php file and try for yourself.

ETbyrne 03-03-2008 01:24 AM

Don't forget sprinf() and fprintf()! :-P

You could also use include(), include_once(), require() , and require_once().

Aaron 03-03-2008 03:39 AM

ummm
PHP Code:


#include <iostream.h> 
using namespace std
 
 
int main() 

  
cout << "Hello World"
  return 
0



ReSpawN 03-03-2008 06:22 AM

Quote:

Originally Posted by StevenF (Post 11845)
He didn't say using only PHP. I guess that what Salathe was getting at.

Scroll three posts up dude.

sketchMedia 03-12-2008 05:30 PM

Quote:

Originally Posted by Aaron (Post 11875)
ummm
PHP Code:

#include <iostream.h> 
using namespace std

int main() 

  
cout << "Hello World"
  return 
0



i lol'd. good ol' std::cout eh?

Nor 03-13-2008 01:36 PM

Quote:

Originally Posted by Salathe (Post 11800)
PHP Code:

Hello World


;) thats funny

Austin6641 03-13-2008 10:33 PM

There is always this:
PHP Code:

<?php
die("Hello World!");
?>

It would cause problems if you wanted to execute code after that though...

Orc 03-13-2008 11:09 PM

PHP Code:

<?= "Hello World." ?>


ReSpawN 03-14-2008 01:41 PM

PHP Code:

<?php exit('TalkPHP'); ?>


martins256 03-25-2008 06:43 PM

PHP Code:

<?php
header 
("Content-type: image/png");
$im = @imagecreatetruecolor(5120)
      or die(
"Cannot Initialize new GD image stream");
$text_color imagecolorallocate($im255255255);
imagestring($im253,  "Talk"$text_color);
$text_color imagecolorallocate($im24612248);
imagestring($im2293,  "PHP"$text_color);
imagepng($im);
imagedestroy($im);
?>


Orc 03-26-2008 01:47 AM

Quote:

Originally Posted by martins256 (Post 12789)
PHP Code:

<?php
header 
("Content-type: image/png");
$im = @imagecreatetruecolor(5120)
      or die(
"Cannot Initialize new GD image stream");
$text_color imagecolorallocate($im255255255);
imagestring($im253,  "Talk"$text_color);
$text_color imagecolorallocate($im24612248);
imagestring($im2293,  "PHP"$text_color);
imagepng($im);
imagedestroy($im);
?>


So simple yet, so good looking xD

sarmenhb 04-28-2008 05:27 AM

Quote:

Originally Posted by Orc (Post 12805)
So simple yet, so good looking xD

wow i didnt know you can do that with php

ReSpawN 04-28-2008 06:45 AM

Search the web for GD library. And uh, why start a silent command (@imagecreatetruecolor) and then call up the or die ("..") function...? Couldn't you then just better $im = @imagecreatetruecolor(...); if (!$im) { exit('DieCommand'); }

sketchMedia 04-28-2008 10:54 AM

PHP Code:

die(chr(0x54) . chr(0x61) . chr(0x6C) . chr(0x6B) . chr(0x70) . chr(0x68) . chr(0x70)); 


Kalle 05-22-2008 01:41 PM

HTML Code:

<p>Hello TalkPHP!</p>
=P

ReSpawN 05-22-2008 06:28 PM

*sigh* ...

Didn't see this one yet.
PHP Code:

die('Bye Bye TalkPHP'); 


delayedinsanity 05-22-2008 07:42 PM

Quote:

Didn't see this one yet.
You beat yourself to it by using exit() earlier, but this person also did. ;)

http://www.talkphp.com/tips-tricks/2...html#post12378

Kalle 05-23-2008 10:31 AM

As in response to ReSpawN's exit() code:
You can't use exit()'s parameter to specify a shutdown message, thats why we have die(). exit()'s parameter is an integer that tells the shutdown code.

exit(0); means that the program shutdown correct just like in C++:

Code:

int main()
{
        return 0;
}

;-)

Salathe 05-23-2008 11:39 AM

exit can take a string argument (in place of the usual integer). If the argument is a string, it gets printed just before exiting just like with die. Try it. :-)

Jim 05-23-2008 12:53 PM

Hai
Can Has Stdio?
Visible "hai Talkphp"
Kthxbye

TexasMd91 06-12-2008 08:27 PM

By typing it...

Never said it had to be in PHP. XD

Village Idiot 06-25-2008 03:18 PM

PHP Code:

$im = @imagecreatefromJPEG("bg.jpg");
$black imagecolorallocate($im000);
imagestring($im352"Hello TalkPHP"$black);
header("content-type: image/jpeg");
echo 
imagejpeg($im);
imagedestroy($im); 


Oilik 07-27-2008 04:11 PM

Quote:

Originally Posted by Jim (Post 14840)
Hai
Can Has Stdio?
Visible "hai Talkphp"
Kthxbye

xD lolcode. :P


Mah way of outputting data without using echo/print:
PHP Code:

<?php
system
("echo wut");
?>

...hey i didn't use php's echo. :(

Dr_Neffy 08-22-2008 06:40 AM

PHP Code:

<?php
$a 
= array("TalkPHP Rulez\n");
print_r($a);
?>

or with a system and without any echo or print
PHP Code:

<?php
system
("perl -e 'printf `hi TalkPHP\n`'");
?>

(lol)

wiifanatic 08-23-2008 12:25 AM

Code:

document.write('O HAI');

rune_kg 08-23-2008 08:03 AM

The same, but different
 
<?=`echo Hello_World`?>

zendkush 08-26-2008 08:32 AM

Use a java bridge!
Code:

// action handler to fill button
function clicked($sender, $e) {
  $win = new Mono("Gtk.Window", "phpinfo()");
  $win->set_DefaultWidth(640);
  $win->set_DefaultHeight(400);
  $pane = new Mono("Gtk.ScrolledWindow");
  $view = new Mono("Gtk.TextView");
  $buffer = new Mono("Gtk.TextBuffer", new Mono("Gtk.TextTagTable"));
  ob_start();
  phpinfo();
  $buffer->set_Text(ob_get_contents());
  ob_end_clean();
  $view->set_Buffer($buffer);
  $pane->add($view);
  $win->add($pane);
  $win->ShowAll();
 }
 $btn = new Mono("Gtk.Button", "Show output from phpinfo()");
 $btn->add_Clicked(new Mono(
                                "System.EventHandler",
                                mono_closure($this, "clicked")));
// then send button to window.


zspencer 09-02-2008 06:04 PM

Howzabout some Error Tossing
 
PHP Code:

<?
ini_set
('display_errors','on');
error_reporting(E_ALL);
trigger_error('Woah, error d00d',E_USER_NOTICE);
?>

What? It works. You can even execute stuff after it too :-D

Ross 09-02-2008 08:16 PM

PHP Code:

file_put_contents('error.html''<p>error\'d</p>');

$ch curl_init('error.html');
// explanatory line
curl_setopt($chCURLOPT_RETURN_TRANSFERfalse);
curl_exec($ch); 


Village Idiot 09-10-2008 03:14 AM

C++
Code:

#include <stdlib.h>
#include <fstream>
using namespace std;
int main()
{
    fstream file_op("test.txt",ios::out);
    file_op<<"Hello World";
    file_op.close();
    system("test.txt");
    return 0;
}

Only tested on windows XP, but should run cross platform.

sketchMedia 09-10-2008 10:52 AM

I can confirm it compiles on linux, although you may need to change the line:
cpp Code:
system("test.txt");
to something like
cpp Code:
system("cat test.txt");//cat vi nano whatever
 
so linux knows what to do with it.

in a similar vein, heres ruby:
ruby Code:
File.open('test.txt', 'w') {|f| f.write("Hello World \n\r") }
exec("cat test.txt")

erect 12-02-2008 09:59 PM

how about breaking out of php and just getting the html to output?

PHP Code:

?>text to this page<?

no echo's or print's involved


All times are GMT. The time now is 04:47 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0