Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
CREATE TABLE my_table ( id INT AUTO_INCREMENT, first_name VARCHAR(100), last_name VARCHAR(100), PRIMARY KEY (id) ); INSERT INTO my_table(first_name, last_name) VALUES ('Chad', 'Hawk'), ('Ned', 'Flanders'), ('Dave', 'Jonson'), ('Newt', 'G'), ('Bill', 'Ng'), ('Norton', 'Who'), ('Alan', 'Joyce'), ('John', 'Smith'), ('Jeff', 'Johnson');

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php // $mysqli is already declared as a working database connection by this sandbox // $value may be a string or a flat array function mask($value) { return preg_replace('/^.{0,3}\K.*/', '***', $value); } $result = $mysqli->query("SELECT * FROM my_table"); foreach ($result as $row) { printf("%s %s\n", mask($row['first_name']), mask($row['last_name'])); }
Copy Clear