PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table `station` (`id` int, `name` varchar(64)); insert into `station` values (1, 'Station1 Name'), (2, 'Station2 Name');
Copy Clear
Copy Format Clear
<?php function get_ids($str) { preg_match_all('/\[id\]([0-9]+)\[\/id\]/m', $str, $ids); return $ids[1]; } function id_to_link($id){ global $mysqli; $stmt = $mysqli->prepare('SELECT `id`,`name` FROM `station` WHERE `id` = ?'); $stmt->bind_param("i", $id); $stmt->execute(); while($station = $stmt -> fetch()) { return '[<a href="/'.$station['id'].'">'.$station['name'].'</a>]'; } } $ids = get_ids('Всем привет [id]1[/id]. Есть новое на [id]2[/id]'); foreach ($ids as $id) { echo id_to_link($id); } printf("Current PHP version: %s \n", phpversion()); $query = "SELECT VERSION() as version;"; $stmt = $pdo->prepare($query); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); printf('DB version: %s', $row['version']);
Show:  
Copy Clear