Jump to content

sasa

Staff Alumni
  • Posts

    2,804
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by sasa

  1. try <?php $str = '<div class="s_ach_stat">10<img src="../images/achievements/tiny_shield.gif"> (01-13-2009) </div> <span>Explore Storm Peaks</span><span class="achv_desc">Explore Storm Peaks, revealing the covered areas of the world map.</span>'; $pattern = '/<div class="s_ach_stat">(\d+)<img[^>]+>\s*\(([^\)]*)\)\s*<\/div>\s+<span>([^<]*)<\/span><span[^>]*>([^<]*)</s'; preg_match($pattern, $str, $arr); echo '<pre>',print_r($arr, true),'</pre>'; ?>
  2. try <?php $test[] = "dd-MMM-yyyy"; // should return a TRUE because d is in the string, and there are no square braces $test[] = "[$-F800]dddd\,\ mmmm\ dd\,\ yyyy"; // should return a TRUE because there is a d in the string outside of the square braces $test[] = "[Red]dddd\,\ mmmm\ dd\,\ yyyy"; // should return a TRUE because there is a d in the string outside of the square braces, even though there is also a d within the square braces $test[] = "[Red]#,##0.00;[Green]-#,##0.00"; // should return a FALSE because there is no d in the string outside of the square braces $test[] = "#,##0.00"; $char = 'd'; $pattern = '/(^|\])[^\[]*'.$char.'/'; foreach ($test as $t){ echo $t,' -> ', preg_match($pattern,$t) ? 'TRUE' : 'FALSE', "<br />\n"; } ?>
  3. 'SELECT SUM(price) as hour_total, LEFT(`time`, 2) as h FROM golfpro_barsales WHERE date = '.$date.' GROUP BY LEFT(`time`,2)'
  4. look coments <?php for($count = 0; $count <= 10; $count++ // first increment variable $count ){ if($count == 12){ echo "Four: " . $count . "<br>"; } else echo $count . "<br>"; $count++; // 2nd increment variable $count } just remove ones of this <?php for($count = 0; $count <= 10; ){ if($count == 12){ echo "Four: " . $count . "<br>"; } else echo $count . "<br>"; $count++; } or <?php for($count = 0; $count <= 10; $count++){ if($count == 12){ echo "Four: " . $count . "<br>"; } else echo $count . "<br>"; }
  5. ups i don't change variable $i in while loop change while loop to while ($i < $num) { $sql1[] = "('" . $_GET[$i.'date']."','".$_GET[$i.'company']."','".$_GET[$i.'product']."','".$_GET[$i.'serial']."','".$_GET[$i.'mac']."')"; $i++; }
  6. try <?php $con = mysql_connect("localhost", "", "") or die(mysql_error()); $i = 0; $num = $_GET[row-total]; mysql_select_db("ipendpoi_mac", $con); $sql = "INSERT INTO details (date, company, product, serial, mac) VALUES "; //echo $sql; while ($i < $num) { $sql1[] = "('" . $_GET[$i.'date']."','".$_GET[$i.'company']."','".$_GET[$i.'product']."','".$_GET[$i.'serial']."','".$_GET[$i.'mac']."')"; } $sgl .= implode(", \n", $sql1); echo $sql; //$sql = substr($sql,0,-1); //this will remove last comma if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo $sql; echo "record/s added" . "< >< >" . "<a href=\"http://www.ipendpoints.co.uk/mac/\">Back";mysql_close($con) ?>
  7. sorry you must GROUP BY title not devname
  8. SELECT title, devname, genre, GROUP_CONCAT(pubname SEPARATOR ', ') as pubnames, sysname FROM table_name GROUP BY pubname
  9. try <?php $example = array ( 52 => array ( 'title' => 'Website Navigation', 'path' => '', 'type' => '115', 'pid' => 0, 'hasChildren' => 1, 'children' => array ( 53 => array ( 'title' => 'Home', 'path' => '<front>', 'type' => '118', 'pid' => 52, 'hasChildren' => 0, ), 54 => array ( 'title' => 'Features', 'path' => 'features', 'type' => '374', 'pid' => 52, 'hasChildren' => 1, 'children' => array ( 59 => array ( 'title' => 'artistic', 'path' => 'features/artistic', 'type' => '374', 'pid' => 54, 'hasChildren' => 1, 'children' => array ( 63 => array ( 'title' => 'galleries', 'path' => 'features/artistic/galleries', 'type' => '374', 'pid' => 59, 'hasChildren' => 1, 'children' => array ( 65 => array ( 'title' => 'graphics', 'path' => 'features/artistic/galleries/graphics', 'type' => '118', 'pid' => 63, 'hasChildren' => 0, ), 67 => array ( 'title' => 'mixed medium', 'path' => 'features/artistic/galleries/mixed-medium', 'type' => '118', 'pid' => 63, 'hasChildren' => 0, ), 64 => array ( 'title' => 'overview', 'path' => 'features/artistic/galleries', 'type' => '118', 'pid' => 63, 'hasChildren' => 0, ), 68 => array ( 'title' => 'photography', 'path' => 'features/artistic/galleries/photography', 'type' => '118', 'pid' => 63, 'hasChildren' => 0, ), 66 => array ( 'title' => 'traditional', 'path' => 'features/artistic/galleries/traditional', 'type' => '118', 'pid' => 63, 'hasChildren' => 0, ), ), ), 62 => array ( 'title' => 'overview', 'path' => 'features/artistic', 'type' => '118', 'pid' => 59, 'hasChildren' => 0, ), 69 => array ( 'title' => 'tutorials', 'path' => 'features/artistic/tutorials', 'type' => '374', 'pid' => 59, 'hasChildren' => 1, 'children' => array ( 71 => array ( 'title' => 'by category', 'path' => 'features/artistic/tutorials/by-category/', 'type' => '118', 'pid' => 69, 'hasChildren' => 0, ), 72 => array ( 'title' => 'by date', 'path' => 'features/artistic/tutorials/by-date/', 'type' => '118', 'pid' => 69, 'hasChildren' => 0, ), 70 => array ( 'title' => 'overview', 'path' => 'features/artistic/tutorials', 'type' => '118', 'pid' => 69, 'hasChildren' => 0, ), ), ), ), ), 58 => array ( 'title' => 'overview', 'path' => 'features', 'type' => '118', 'pid' => 54, 'hasChildren' => 0, ), 61 => array ( 'title' => 'projects / labs', 'path' => 'features/projects-labs/', 'type' => '374', 'pid' => 54, 'hasChildren' => 0, ), 60 => array ( 'title' => 'web development', 'path' => 'features/web-development', 'type' => '374', 'pid' => 54, 'hasChildren' => 1, 'children' => array ( 74 => array ( 'title' => 'articles', 'path' => 'features/web-development/articles/', 'type' => '374', 'pid' => 60, 'hasChildren' => 0, ), 73 => array ( 'title' => 'overview', 'path' => 'features/web-development', 'type' => '118', 'pid' => 60, 'hasChildren' => 0, ), 75 => array ( 'title' => 'tutorials', 'path' => 'features/web-development/tutorials', 'type' => '374', 'pid' => 60, 'hasChildren' => 0, ), ), ), ), ), 55 => array ( 'title' => 'Activity', 'path' => 'activity', 'type' => '374', 'pid' => 52, 'hasChildren' => 0, ), 56 => array ( 'title' => 'Blog', 'path' => 'blog', 'type' => '374', 'pid' => 52, 'hasChildren' => 0, ), 57 => array ( 'title' => 'About', 'path' => 'about', 'type' => '374', 'pid' => 52, 'hasChildren' => 1, 'children' => array ( 76 => array ( 'title' => 'the author', 'path' => 'about/the-author', 'type' => '118', 'pid' => 57, 'hasChildren' => 0, ), 77 => array ( 'title' => 'the website', 'path' => 'about/the-website', 'type' => '118', 'pid' => 57, 'hasChildren' => 0, ), ), ), ), ), ); function add_depth($array, $depth=0){ foreach ($array as $k => $a){ if ($depth) $array[$k]['depth'] = $depth; if ($a['hasChildren']) $array[$k]['children'] = add_depth($a['children'], $depth+1); } return $array; } $example = add_depth($example); print_r($example); ?>
  10. try <?php $page = $_GET['page']; if($page) include("$page.php"); else include("main.php"); ?>
  11. SELECT * FROM (customers m LEFT JOIN orders o ON m.id = o.customers_id) WHERE o.id IS NULL
  12. declare variable at start of function $output = '';
  13. sasa

    [SOLVED] REGEX

    or <?php $test = '(game (name test) (valueb something) (etc) (etc) (etc)) (game (name test2) (valueb something) (etc) (etc) (etc)) // this is just a 3 line example ,it can be on 1 line or on 10 //thats how a doccument will look,i (need to group everything from "(group till the two ))" anyone know how i can do this with regex? thank you'; $len = strlen($test); $out = array(); $count = 0; $part = ''; for ($i = 0; $i < $len; $i++){ if ($test[$i] == ')') $count--; if ($count > 0) $part .= $test[$i]; elseif ($part){ $out[] = $part; $part = ''; } if ($test[$i] == '(') $count++; } print_r($out); ?>
  14. add one more / after http:/
  15. you just remove space after TEXT
  16. or <?php $Ehighnote = array('E','F','F#','G','G#','A','A#','B','C','C#','D','D#','E'); $test = '|----2----4-1-10-10-12-10---3|----2h3p0--|'; echo preg_replace("/(?<=-|\|)(\d+)(?=-|\|)/e",'\$Ehighnote["\1"]', $test); ?>
  17. try <?php function navigate($path, $array){ $path = explode(':',$path); $key = array_shift($path); if (!is_array($array) or !array_key_exists($key, $array)) return 'error'; $path = implode(':',$path); if (!strlen($path)) return $array[$key]['name']; else return navigate($path, $array[$key]['info']); } $test = array( array( 'name' => 'Directory 1', 'info' => array( array( 'name' => 'File 1.a', 'info' => 'foo'), array( 'name' => 'File 1.b', 'info' => 'foo'), array( 'name' => 'File 1.c', 'info' => 'foo') ) ), array( 'name' => 'File 2', 'info' => 'foo' ) ); $path = "0:1"; echo navigate($path, $test); ?>
  18. try <?php $test = '<p class="smallTitles" align="center">SETD2120 ESTELLE DINING</p><table width="625" border="0" cellspacing="0" cellpadding="0"><tr><td colspan="3" align="middle" valign="middle"><img src="/wc/Pictures/2120.jpg"></td></tr><tr><td width="300" align="left" valign="top">Bookmatched cherry veneer double pedestal table with hand carved solid wood apron. Oversized back chair with brass nailheads, hand carved solid wood arms and pillaster legs.</td><td width="22" align="left" valign="top"> </td><td width="350" align="left" valign="top"><span class="catalogDesc"><Strong>SETD2120</strong> ESTELLE DINING<br /><br /><br />Qty SKU # <br /><table cellspacing=0><tr><td valign=top; nowrap> 1<strong> 2120T-TOP-N</strong> </td><td valign=top>ESTELLE DINING TABLE TOP (W/2X18"L)</td></tr></table><table cellspacing=0><tr><td valign=top; nowrap> 1<strong> 2120T-LEG-N</strong> </td><td valign=top>DOUBLE PEDESTAL TABLE BASE 31.5"H</td></tr></table><table cellspacing=0><tr><td valign=top; nowrap> 2<strong> 2120A-ASSEMBLED</strong> </td><td valign=top>ESTELLE ARM CHAIR 44"H</td></tr></table><table cellspacing=0><tr><td valign=top; nowrap> 4<strong> 2120S-ASSEMBLED</strong> </td><td valign=top>ESTELLE SIDE CHAIR 44"H</td></tr></table><table cellspacing=0><tr><td valign=top; nowrap> 1<strong> 2120-B-N</strong> </td><td valign=top>ESTELLE BUFFET 33"H</td></tr></table><table cellspacing=0><tr><td valign=top; nowrap> 1<strong> 2120-H-N</strong> </td><td valign=top>ESTELLE HUTCH 56 3/4"H</td></tr></table></td></span></td></tr></table><p> </p>'; $pattern = '~<table cellspacing=0><tr><td valign=top; nowrap>.*?<strong>( )*([^<]+)</strong>[^<]+</td><td valign=top>([^<]+)</td></tr></table>~'; preg_match_all($pattern, $test, $out); $out = array_combine($out[2], $out[3]); print_r($out); ?>
  19. try ... echo '</tr>'; ?> <input type="hidden" name="item_name[]" id="item_name" value="<?=$name?>"> <input type="hidden" name="amount[]" id="amount" value="<?=$price?>"> <input type="hidden" name="quantity[]" id="quantity" value="<?=$qty?>"> <?php } echo '</table>'; ...
  20. try if($ll = mysql_fetch_assoc($res)) $line = array_merge($line,$ll);
  21. try $comm_f = file_get_contents('style/comm_template.html'); $query = "SELECT * FROM `{$comm_conn->table_s}` WHERE `public` = 'true' ORDER BY `timestamp` DESC"; $res = $comm_conn->query($query); while($d = mysql_fetch_assoc($res)) { static $c = 0; ... you query database again in each loop
  22. you can't break php code between if and else blocks <?php if (blah){ //some code } ?><?php // you can't break php code here else { //more code } ?>
  23. try <?php $test = '<link rel="shortcut icon" href="/cms/images/favicon.ico" /> <link href="/cms/templates/rt_versatility4_j15/css/template_css.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/menustyle4.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/style2.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/typography.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/system/css/system.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/system/css/general.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/rokslidestrip.css" rel="stylesheet" type="text/css" /> <link href="/cms/templates/rt_versatility4_j15/css/rokmoomenu.css" rel="stylesheet" type="text/css" /> '; echo preg_replace_callback('/(\shref=")(.*?)(")/is', 'code', $test); function code($x){ return $x[1].base64_encode($x[2]).$x[3]; } ?>
  24. try <?php function comb($a, $len){ if ($len > count($a))return 'error'; $out = array(); if ($len==1) { foreach ($a as $v) $out[] = array($v); return $out; } $len--; while (count($a) > $len) { $b = array_shift($a); $c = comb($a, $len); foreach ($c as $v){ array_unshift($v, $b); $out[] = $v; } } return $out; } $test = array(1,2,3,4,5,6,7,8,9,10,11,12); $a = comb($test,6); print_r($a); ?>
×
×
  • 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.