Category Archives: PHP

Multibyte PHP Functions

Source: Using Multi-Byte Character Sets in PHP (Unicode, UTF-8, etc) The following list details the PHP string functions which could cause problems when handling multi-byte strings. The multi-byte safe alternative is given when available: mail() Try mb_send_mail() instead. strlen() Try mb_strlen() instead. strpos() Try mb_strpos() instead. … Continue reading

Posted in PHP | Tagged , , | Leave a comment

Inserting a troublesome string from PHP to Javascript

<script type=”text/javascript”> alert(“<?php echo preg_replace(“/\r?\n/”, “\\n”, addslashes($message)); ?>”); </script>  Passing variables to Javascript

Posted in PHP | Tagged | Leave a comment

How to get next MySQL insert id

function getMysqlInsertID($tablename) { $next_increment = 0; $qShowStatus = “SHOW TABLE STATUS LIKE ‘$tablename’”; $qShowStatusResult = mysql_query($qShowStatus) or die ( “Query failed: ” . mysql_error() . “<br/>” . $qShowStatus ); $row = mysql_fetch_assoc($qShowStatusResult); $next_increment = $row['Auto_increment']; return $next_increment; }

Posted in MySQL, PHP | Tagged , | Leave a comment

Run php as cronjob with safe_mode setting

/usr/bin/php -d safe_mode=Off script_to_run.php

Posted in PHP | Tagged , | Leave a comment

ctags for php

$ cd /path/to/phpcode $ ctags -f /output/tags \ -h “.php” -R \ –exclude=”\.svn” \ –totals=yes \ –tag-relative=yes \ –PHP-kinds=+cf \ –regex-PHP=’/abstract class ([^ ]*)/\1/c/’ \ –regex-PHP=’/interface ([^ ]*)/\1/c/’ \ –regex-PHP=’/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/’ exuberant ctags with … Continue reading

Posted in Editor, PHP, vim | Tagged , | Leave a comment

PHP deprecated eregi, ereg_replace, split replacement

Deprecated       eregi($pattern, $haystack); Replacement       preg_match(‘/’ . $pattern . ‘/i’, $haystack); Deprecated       ereg_replace($pattern, $replacement, $haystack); Replacement       preg_replace(‘/’ . $pattern . ‘/’, $replacement, $haystack); Deprecated       split(“[:,]“, “1:2,3:4,5:6″); … Continue reading

Posted in PHP | Tagged , , | Leave a comment

Prohibit execution of PHP scripts inside include directory

Create a PHP file /** * prepend_goto_index.php */ header(‘Location: http://’ . $_SERVER['HTTP_HOST']); Inside the include directory, create .htaccess file php_value auto_prepend_file prepend_goto_index.php

Posted in PHP | Tagged , | Leave a comment

Disable PHP in directory

In .htaccess php_flag engine off

Posted in Apache2, PHP | Tagged , | Leave a comment

How to create reverse traceroute page on your website using PHP

<?php $result = exec(‘traceroute ‘ . $_SERVER["REMOTE_ADDR"], $lines); echo ‘<h1>Your IP is ‘ . $_SERVER["REMOTE_ADDR"] . ‘</h1>’; echo ‘<pre>’; foreach ($lines as $n => $line) { if ($n) echo ‘<br />’; echo $line; } echo ‘</pre>’; echo ‘<p>-end-</p>’; Here’s how … Continue reading

Posted in Linux Administration, PHP, Programming | Tagged , , | Leave a comment