Jump to content

five

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Everything posted by five

  1. i wrote this function breakAt(array $positions, $str) { $prev = 0; foreach ($positions as $pos) { $arr[] = substr($str, $prev, $pos-$prev); $prev = $pos; } $arr[] = substr($str, $pos); return $arr; } function str_splitByPreg($pattern, $str) { foreach (str_split($str,1) as $pos => $char) if (preg_match($pattern, $char)>0) $brkPos[$pos] = $pos; return (empty($brkPos)) ? array($str) : breakAt($brkPos, $str); } function str_splitBy($byFunc, $str) { foreach (str_split($str,1) as $pos => $char) if ($byFunc($char)) $brkPos[$pos] = $pos; return (empty($brkPos)) ? array($str) : breakAt($brkPos, $str); } function isLowerCase($char) { if ( (ord($char) > 96) && (ord($char) < 123) ) return TRUE; return FALSE; } print_r(str_splitBy('isLowerCase', $str)); print_r(str_splitByPreg('/[a-z]/', $str));
  2. i think this will work $string = "this is one 1 one string 1111one 11"; $replace = array('one'=>'1', '1'=>'one'); echo strtr($string, $replace);
  3. well i thought there may be more patterns to match in your actual code than just two and this way you can just add up to the array. could you post the working code? just curious
  4. first off positioning your php code inside html is not that hard and it is not necessary to use a variable. you can close tags. like if i do some html here<br /> <?php // some php code here ?> now a html table follows<br /> <table> <tr> <td width="250"> </td> <td>now i want some php code to be executed to output something in this cell so.. <?php $variable = '<b>something</b>'; echo $variable; echo '123456789'; ?> and still in the same cell i got some more html like <u>this</u> </td> </tr> </table> also why not write valid html? i think all tables need to have a <tr> tag even if they have just one. when you say all rows? i see only one row, which contains a cell, which contains a table with two cells. you can also echo gettemplate("profile");
  5. if ($counter == 1) { // do the output, echo mysql result } else { echo "your td here, with the $counter thing"; $counter++ } think so
  6. $b = file_get_contents("https://".$username.":".$password."@localhost:2083/frontend/x3/sql/addb.html?db=archive");
  7. well assuming $_SESSION variables contain filenames right? not the actual header, which is supposed to be in a file.. <?php $allowed = array("CEL150.php","celcius_conn.php",$_SESSION['header'],$_SESSION['conn-read'] ); function get_include_contents($fullPath) { global $allowed; $filename = pathinfo($fullPath, PATHINFO_FILENAME); $pathname = pathinfo($fullPath, PATHINFO_DIRNAME); if (! in_array($filename, $allowed)) { $_SESSION['error_msg'] = "Failed access to file Error 201-0"; $_SESSION['error_code'] = 1; header("Location: ../apps/error.php"); } else { if (is_file($pathname.$filename)) { $cwd = pathinfo($_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'], PATHINFO_DIRNAME); $contents = file_get_contents('http://' . $cwd . $filename); } else { $_SESSION['error_msg'] = "Failed access to file Error 201-1"; $_SESSION['error_code'] = 1; header("Location : ../apps/../apps/error.php"); exit(); } } } something like that will do a file_get_contents pretty much simulating what a user would see in his browser if he used this url. helps?
  8. so basically you only care about the output of included files code.. why not use file_get_contents() ?
  9. assuming your database is named 'database' and has a table named 'database' which contains 'DATE' and 'PLOST' columns.. <?php $dbFieldNames['date'] = 'DATE'; $dbFieldNames['plost'] = 'PLOST'; $patternsMatch['date'] = "/local time/"; $patternsMatch['plost'] = "/packets lost/"; $patternsReplace['date'] = '/^local time is: (\S+ \S+ \d+ \d+:\d+:\d+) \S+ \d+$/'; $patternsReplace['plost'] = '/^\[REPORT\] Total packets lost\s+: \d+ \((\d+)%\)$/'; $c = mysql_connect("localhost", "root", "passwd") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $data = file_get_contents("test.txt"); foreach ($patternsMatch as $type => $patMatch) { if (preg_match($patMatch, $current_line)) $matchStore[$type] = preg_replace($patternsReplace[$type],'\1',$data); } if (parser($matchStore)) echo "success!"; else echo "fail..".mysql_error(); function parser(array $match_Store) { global $c, $dbFieldNames; $values = $fields = ""; foreach ($match_Store as $type => $matchCount) { $fields .= $dbFieldNames[$type] . ","; $values .= "'$matchCount',"; } $fields = substr($fields, 0, -1); $values = substr($values, 0, -1); $sql = "INSERT INTO database ($fields) VALUES ($values)"; return mysql_query($sql, $c); } ?> INSERT syntax is INSERT INTO tableName (FIELD_NAME_1, FIELD_NAME_2) VALUES (VALUE_1, VALUE_2)
  10. i think phpMyAdmin is open source. not sure though.. another option that might work on your .sql file may be exploding in ";\n"
  11. okay. probably the explode is simplistic. are you sure that in your sql file every query ends with ; ? like if there is a query that ends with a line break phpMyAdmin may be parsing it correctly.. but your explode will put two queries (or more) as one query.
  12. well in your database you got a table named tags which has a column named tag where there are several tags for each news id.. so i assume you got the same news_id in many records for a bunch of tags. so $glue_t = array(); $sql = "SELECT * FROM tags"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { $news_id = $row['news_id']; if ($news_id == $id) { $glue_t[] = $row['tag']; } } echo implode("; ", $glue_t);
  13. considering the $glue_t array, on the second time it will run through the loop is not clear, so it contains data from the previous loop. if that is the case use if (isset($glue_t) unset($glue_t); or simply $glue_t = array(); in the beginning of the while loop..
  14. i think it would be better to use something like <?php if (!isset($_POST['cpass'])) { ?> html form here <form name="myform" method="post" action="setup.php"> ... </form> <?php } else { $pass = $_POST['cpass']; // now do stuff } since what you want to do is use the same file, the way you have it it will always try to get the password from $_POST, even if that is not set as when the user sees the form. Also a minor fix in your form tag so to specify you need post and to use setup.php as the processing file of the form. also are you sure it connects to mysql ?
  15. maybe this will do if ( (isset($a)) && (isset($b)) && (isset($c)) && (isset($d)) ) { // your code here
×
×
  • 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.