Use print() to send a formatted string to PHP's output stream:
print()
const php = @import("php/root.zig"); pub fn @"call show"(_: *@This(), args: struct { string: []const u8, int: u32, float: f64, bool: bool, point: struct { x: f64, y: f64 }, }) !void { php.print("\"{s}\", 0x{x} {d} {} {}\n", .{ args.string, args.int, args.float, args.bool, args.point, }); }
<?php show("Hello world", 0xDEAD_BEEF, M_PI, false, [ 'x' => 123, 'y' => 456 ]);
"Hello world", 0xdeadbeef 3.141592653589793 false .{ .x = 123, .y = 456 }
Use write() to write a block of data and flush() to flush the output stream:
write()
flush()
const php = @import("php/root.zig"); pub fn @"call write"(_: *@This(), args: struct { bytes: []const u8, }) !void { const written = try php.write(args.bytes); php.print("written = {d}\n", .{written}); php.flush(); }
<?php write("Hello world\n");
Hello world written = 12
There was an error while loading. Please reload this page.