Jump to content

sasa

Staff Alumni
  • Posts

    2,804
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by sasa

  1. try <?php $text = '<p>stuff before</p> <!-- <p>stuff</p> SomeKeyword <p>stuff</p> --> <!-- <p>stuff</p> MyKeyword <p>stuff</p> --> <p>stuff after</p>'; preg_match('/^(.*)(<!--.*?MyKeyword.*?-->)(.*)$/s', $text, $out); print_r($out); ?>
  2. try <?php $text = '<a href="http://www.yoursite.com"> blah blah <a href="http://www.yoursite.com/xxx"> <a href="http://www.mysite.com?url=http://www.yoursite.com/11"> <a href=".../exit.php?url=http://www.mysite.com">'; $text = preg_replace('#(?<=\<a href="http://)(?!www\.mysite\.com)([^"]*)#', 'www.mysite.com?url=http://\1', $text); print_r($text); ?>
  3. sasa

    Help with some

    can you post the URL from where you grab data
  4. try arrays.php <?php $somearray = array(); ?> test.php <?php include('arrays.php'); print_r($somearray); $somearray[]= rand(1,1000); $new = var_export($somearray,true); $text = file_get_contents('arrays.php'); $tex = preg_replace('/(?<=\$somearray = )[^;]*(?=;)/is', $new, $text); $file = fopen('arrays.php', 'w'); fputs($file, $tex); fclose($file); ?>
  5. try <?php function num_to_word($num, $tri=0) { $ones = array("", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen"); $tens = array("", "", " twenty", " thirty", " forty", " fifty", " sixty", " seventy", " eighty", " ninety"); $triplets = array("", " thousand", " million", " billion"); $r = (int) ($num / 1000); $x = ($num / 100) % 10; $y = $num % 100; $str = ""; if ($x > 0) $str = $ones[$x] . " hundred"; if ($y < 20) $str .= $ones[$y]; else $str .= $tens[(int) ($y / 10)] . $ones[$y % 10]; if ($str != "") $str .= $triplets[$tri]; if ($r > 0) return convertTri($r, $tri+1).$str; else return $str; } for ($i = 1; $i<=50; $i++) $out[$i] = ucfirst(trim(num_to_word($i))); print_r($out); ?>
  6. change $req = 'SELECT username, avatar FROM users WHERE username =".$username_m." '; to $req = 'SELECT username, avatar FROM users WHERE username ="'.$username_m.'"';
  7. try <?php $text = 'your message is: lets say i explode around a space character..'; $text = explode(' ', $text, 4); echo $text[3]; ?>
  8. try <?php $host = "name"; str_ireplace(array("array", "array2", "array3"), "", $host, $test); if ($test > 0) {print "results true"; } else{ print "results false"; }?>
  9. try <?php function economy_percent() { // users $sql = "SELECT SUM(`ammo`) AS s_ammo,SUM(`bank`) AS s_bank,SUM(`money`) AS s_money,SUM(`titanium`) AS s_titanium,SUM(`uranium`) as s_uranium FROM cf_users"; $rs = @mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error()); $row = mysql_fetch_assoc($rs); // global $sql1 = "SELECT SUM(`treasury`) as total FROM cf_global"; $rs1 = @mysql_query($sql1) or die('Query:<br />' . $sql1 . '<br /><br />Error:<br />' . mysql_error()); $row1 = mysql_fetch_assoc($rs1); $economy = (($row['s_ammo'] + $row['s_bank'] + $row['s_money'] + $row['s_titanium'] + $row['s_uranium']) / 5); $treasury = $row1['total']; $economy_percentage = (($treasury / $economy) * 100); // line 104 return $economy_percentage; }; ?>
  10. sasa

    Help with some

    $out[6][1]
  11. try <?php $text = '<br>Statistics: March: Model 55: Slow [Random stuff here..] <br>Statistics: April: Model 55: Medium [Random stuff here..] <br>Statistics: May: Model 55: Fast [Random stuff here..] <br>Statistics: June: Model 55: Medium [Random stuff here..]'; $key_word = 'Statistics:'; $start = strrpos($text, $key_word) + strlen($key_word); $out = substr($text, $start, 35); echo $out; ?>
  12. sasa

    Help with some

    try <?php $text = file_get_contents("http://www.battle.net/war3/ladder/w3xp-player-profile.aspx?Gateway=Azeroth&PlayerName=Dayvinn-"); preg_match_all('/ranking(Header|Row)">([^<]*)</', $text, $out); $out = array_chunk($out[2], 4); print_r($out); ?>
  13. try <?php function my_urlencode($a){ return urlencode($a[1]); } echo $result = preg_replace_callback('#href="([^"]*)"#is', 'my_urlencode', $result); ?>
  14. sasa

    Regex Wont Match

    try <?php $string = 'Link : http://link.com Description : Some information Here!!'; preg_match('/link : (?P<Link>[^ ]+) description : (?P<Description>.*)/i',$string, $match); print_r($match); ?>
  15. try <?php $url = 'http://www.youtube.com/watch?v=cW3z70WMCTg'; $sql = "select * from wvideos where locate(vmkey,'$url') "; ?>
  16. try <?php $text = file_get_contents('http://[Website].com'); preg_match_all('/There are now (\d+) .*?(?= 2008\.)/', $text, $out); $max = max($out[1]); $keys = array_keys($out[1], $max); foreach ($keys as $key) echo $out[0][$key],"\n"; ?> you don't need to explode text in line
  17. try <?php foreach( $patharray as $key => $value) { //$latestfile = 0; foreach($patharray as $value2) { $pos = strpos($value2[0], $value[0]); if ($pos === 0){ print $value2[1]; if($patharray[$key][1] < $value2[1]) { $patharray[$key][1] = $value2[1]; } } } } ?>
  18. try <?php $url = 'http://www.youtube.com/watch?v=cW3z70WMCTg'; $url = parse_url($url); parse_str($url['query'],$out); $url = addslashes($out['v']); $sql = "select * from wvideos where vmkey='$url' "; ?>
  19. try <?php $start = true; while($row1 = mysql_fetch_array($result2)) { $Keyword = $row1['keyword']; $KeywordID = $row1['keyword_id']; if ($start) $start = false; else echo ', ';echo $Keyword; } ?>
  20. try <?php $text = 'There are now 5 sales on Wednesday, June 18, 2008. There are now 1023 sales on Thursday, June 19, 2008. There are now 1205 sales on Friday, June 20, 2008. There are now 1205 sales on Saturday, June 21, 2008.'; preg_match_all('/There are now (\d+) .*?(?= 2008\.)/', $text, $out); $max = max($out[1]); $keys = array_keys($out[1], $max); foreach ($keys as $key) echo $out[0][$key],"\n"; ?>
  21. SELECT COUNT( * ) as num_ent1, DATE_FORMAT( `date` , '%Y' ) AS y FROM `table` WHERE 1 GROUP BY y HAVING y >2005 and y<2008
  22. try <?php $text = "<span style='font-weight:bold;'>bla <span style='font-weight:bold;'>some text</span></span>"; echo preg_replace("/(?<=<span style='font-weight:bold;'>)(.*?)<span style='font-weight:bold;'>(.*?)<\/span>(?=<\/span>)/i",'\1\2',$text); ?>
  23. try <?php $text = ' 100005 HELLO WORLD L1 100000HELLO WORLD L2 100010THIS IS A SAMPLE L1'; echo preg_replace('/(?<=1)\d+(?=[a-z][^\n\r]*L1)/i','',$text); ?>
  24. try <?php $a = 'php and and and perl and and html. Is it it OK OK?'; $out = preg_replace('/((\w+)\W)(?=\2)/i','', $a); print_r($out); ?>
×
×
  • 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.