Jump to content

nashruddin

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

About nashruddin

  • Birthday 11/28/2008

Contact Methods

  • Website URL
    http://www.nashruddin.com

Profile Information

  • Gender
    Not Telling

nashruddin's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Here's my class to create image's thumbnail on-the-fly: http://www.nashruddin.com/create-image-thumbnail-on-the-fly.html
  2. Not gonna be easy, but still possible. <?php $string = "<p>[resource type='image' name='photo' id='1' height='100' width='100']</p>"; /* get [resource ...] */ preg_match("/(\[resource[^\]]+\])/", $string, $a); /* get properties from [resource ...] */ preg_match_all("/([\w]+='[\w]+')/", $a[1], $b); /* replace key='val' to key=val */ $c = preg_replace("/([\w]+)='([\w]+)'/", "$1=$2", $b[1]); /* convert obtained string to associative array */ foreach($c as $line) { list($key, $val) = explode('=', $line); $props[$key] = $val; } print '<pre>'; print_r($props); /* now you have: $props = array ( [type] => image [name] => photo [id] => 1 [height] => 100 [width] => 100 ) */ ?>
  3. adding some tricks: <?php $text = "There are now 1005 sales on Wednesday, June 18, 2008.\n" . "There are now 1023 sales on Thursday, June 19, 2008.\n" . "There are now 1095 sales on Friday, June 20, 2008.\n" . "There are now 1205 sales on Saturday, June 21, 2008.\n"; $lines = explode("\n", trim($text)); $line = $lines[count($lines) - 1]; preg_match("/^There are now (.+), 2008.$/", $line, $matches); echo $matches[1]; /* will print: 1205 sales on Saturday, June 21 */
  4. It's possible. but the 'dynamic' CSS should reside at the HTML page (not in a separate file). Maybe something like this: <?php /* this function selects random image and returns its URL */ function get_random_img() { /* ...some code here... */ } ?> <html> <head> <style type="text/css"> @import url('style.css'); body { background: url('<?php echo get_random_img() ?>'); } </style> </head> ...
  5. Once you have fetched the page contents, use regular expression to extract its data. eg: <TITLE>,<META>,etc. See my tutorial on how to do this: http://www.nashruddin.com/parsing-tags-from-html-page.html
  6. looks like there is a duplicate key when your loop stops. by the way, what is this line? $sql = "INSERT INTO employees () VALUES ('')"; mysqli_query($mysqli, $sql); you insert nothing to the table.
  7. Print current user (windows): <?php echo getenv("USERNAME"); ?>
  8. mysql_fetch_row() returns enumerated array. you access the values with $row[0], $row[1], ...,$row[n]. if you want to access it with $row['id'], $row['region_id'], use mysql_fetch_assoc() instead.
  9. add this line at the top of your HTML: <?php session_start(); ?>
  10. use LIKE operator. ex: SELECT * FROM tableName WHERE columnName LIKE '%$desiredNum%'
  11. Here it is: <?php $favcar = array("volvo", "saab", "opel", "audi"); ?> <select name="favcar"> <option value=""> </option> <?php foreach($favcar as $name) { if ($name == $_GET['favcar']) { print "<option value=\"$name\" selected>$name</option>"; } else { print "<option value=\"$name\">$name</option>"; } } ?> </select>
  12. More simpler syntax: $key = 'empty'; $keycheck = ($key == 'empty') ? '<img src="images/keyneautural.php">' : '';
  13. trim() is not required, we use it just to remove spaces from the beginning and end of a string. Example: if you have this string: <highlight> some text here </highlight> we can remove <highlight> and </highlight> using this code: $str = preg_replace("/<\/?highlight>/", "", $str); which will result in $str = " some text here "; and use trim (optional) to remove the spaces. $str = trim($str) /* $str = "some text here"; */
  14. Use regular expression instead. <?php /* replace all <p ...> with <p> */ $new_string = preg_replace("/<p[^>]*>/", "<p>", $old_string); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.