
printf
Staff Alumni-
Posts
889 -
Joined
-
Last visited
Everything posted by printf
-
My regex makes no sense? I think it's the other way around. The OP asked for a regex that allows for punctuation marks at the end of a sentence, yours allows for repeated punctuation marks anywhere but the beginning of the sentence;;;;;;;:,, which makes no sense to me! If you want to strictly match a English literature sentence, then something like this will work. /^(?:\w+(\, |\; |\: | )){1,}(?:\w+(\.|\!|\?))$/i
-
didn't read, huh! Didn't read, new replies, new posts, new topics are one in the same to me. Since a users last visit, a user will encounter any of those references, if they are implemented. and a new topic, new post, new reply == a not read / unseen, new topic, new post, or new reply since their last visit. I don't believe I am missing the point, as giving a user the opportunity to know what is new / unseen / unread is a necessity but you have to in someway draw the line where that feature becomes impractical. I mean, it's not... see how smart I am, I know what you have viewed or not viewed because I am endlessly tracking you, it's simply giving them the ability to know what's has been going on since their last visit!
-
I didn't say I would do it one way or the other, I just used that as an example, and really how it is done doesn't matter, what matters is the result, which loads a database with junk. Do you really believe a user is interested in topics and posts that are years old... Hi printf, welcome back, did you know you forgot to read a post from 5 years ago... lol!
-
Having features in your software that don't reflect the true facts while using CPU clocks to support that feature is stupid. Let me give you a better example. Most people I know use Google Maps to get directions to go everywhere. And like you stated, 'features like that are pretty cool features', they give you that wow factor! But would you give your '12 year old child' a phone and tell them to use Google Maps to navigate wherever they are wanting to go, I WOULDN'T, why, because your child just might die believing Google Maps is a safe mapping program when it's not, and no that isn't entirely Google's fault, but it is partly their fault, because they don't personal audit every bit of their mapping data. Now, you might say, what does that have to do with what we are talking about, not a lot, but my point is simple, you shouldn't put things out there that just guess at stuff just because you think it's cool. And just so you know, people have gotten lost, even died trusting Google maps. Anyway, back to what I was really wanting to say... My problem isn't so much with the silly features some developers implement, but I do have a problem with how they are implemented. Things like, who's online, total topics, total posts, etc; should not be handled in your script, as they are things that change when another action takes place. Say you add a new topic, that creates a new topic and a new post, so you have to update you totals, (topics & posts) so you run a query or two to do that, instead of using the database to do it for you, trigger(do this), which makes no sense to me. Now compound that simple developers mistake X 10, and you will end up doing (10,000) unneeded things on a forum that generates (1000) new topics / posts a day. That to me tells me whoever developed that software is not a developer, to me they are just a script kiddie doing things in most illogical way...
-
Wow, tables would be filled with tons of junk, not very practical if you ask me. it sort of like the "glass half filled theory", if you start with "posts / topics not viewed", it's like the glass is half full, but when the user starts reading a lot of posts / topics, the database will soon become bloated and the glass half full will become half empty, (just to tell them what topics or post they haven't viewed), like I said, it's not very practical. I always recommend the minimum, highlight posts and topics that are new since they last visited. You know thinking about things like this makes me kind of laugh at developers who waste run-time resources on such silliness when their code base could use a lot of improvement. Its like the other crazy stuff most forum software have, one example... "You have spent 43 days, 7 hours, 14 minutes, and 7 seconds on our forum", to me that is simply stupid, because you cannot maintain 'state', so their implementing a 'where just guessing' is stupid, (period) And yes, I know I am very opinionated, but having spent countless hours modifying forum software for my many clients, I do know what I am talking about!
-
How to perform some filter check on data read from text file into table?
printf replied to thegweb's topic in PHP Coding Help
Okay, based on what you are wanting to do, I will tell you how to do those things... you said.... First I need to know how the data can be sorted by published year... I said.... To do that you will need to go through the whole file and place the valid data into an array, then sort that array on the column that you want to sort on you said... Then if there is any error in my text file like any field missing, say birth year is missing, skip that whole line from my output table and append that line into another text file. I said.... to do that, while you are going through your books database, add a if() condition that test for those missing values. In this case you know your database must contain (5) columns of data, so if(sizeof($line)) , which represents a row of data doesn't equal (5), you would add that line to a 'missing' data file you said... Third filter, is based on published year, if published year is grater than birth year then its an error, again that should skip the line from my output table and append this into another text file. I said.... to do that, while you are going through your books database, add a if() condition that test for those invalid values. So if the publishing year is greater than the birth year. append that line to a 'invalid' data file... Now my simple example... /* books database file 'books.txt' */ title1 John Doe 1960 1935 title2 Jane Doe 1970 1935 title3 John Doe 1935 title4 Jason Doe 1971 1960 title5 Gee Swan 1960 1984 title6 Jane Doe 1935 1970 2015-09-01 Dave Hertner 2000 1984 2001-02-28 Ron Swan 1999 2011-05-20 Mark Ramsay 2001 1980 Now a quick script that you can study... (untested but it should work) <?php // function put in file function putFile ( $file, $data, $new = 'w' ) { $io = fopen ( $file, $new ); fputs ( $io, implode ( ' ', $data ) . "\r\n" ); fclose ( $io ); } // sorting functions // sort newest to oldest function sortA ( $a, $b ) { return ( $a['pyear'] == $b['pyear'] ? 0 : ( $a['pyear'] > $b['pyear'] ? -1 : 1 ) ); } // sort oldest to newest function sortD ( $a, $b ) { return ( $a['pyear'] == $b['pyear'] ? 0 : ( $a['pyear'] < $b['pyear'] ? -1 : 1 ) ); } // books database $db = 'books.txt'; // missing data file $mf = 'missing.txt'; // invalid file ( publising year > birth year ); $if = 'invalid.txt'; // valid row size $vs = 5; // column names $cn = array ( 'title', 'fname', 'lname', 'pyear', 'byear' ); // output container $oc = array (); // db handle $io = fopen ( $db, 'r' ); // read the books db while ( ! feof ( $io ) ) { $line = explode ( ' ', trim ( fgets ( $io, 1048 ) ) ); if ( sizeof ( $line ) != 5 ) { putFile ( $mf, $line, 'a' ); continue; } elseif ( ( int ) $line[3] > ( int ) $line[4] ) { putFile ( $if, $line, 'a' ); continue; } else { $oc[] = array_combine ( $cn, $line ); } } fclose ( $io ); // sort the books array, sort oldest to newest uasort ( $oc, 'sortD' ); // just show the result print_r ( $oc ); ?> -
Something like... "/^[a-z\s]{4,30}+([\.!,;:-?]{1}+)?$/i",
-
could you please post a link to a php info file on the server that is running this code... // link to... <?php phpinfo(); ?>
-
change your code to this.... <?php global $PREFS, $TEMPLATE, $SESSION; include_once SYS_PATH . "includes/ext/ext.anchor.php"; include_once SYS_PATH . "includes/ext/core/ext.lang.php"; include_once SYS_PATH . "includes/ext/core/ext.dropdownlist.php"; include_once SYS_PATH . "includes/ext/core/ext.trim.php"; include_once SYS_PATH . "includes/ext/core/ext.ifelse.php"; ?><?php $_temp_inc = $TEMPLATE->output('header.tpl',0); include($_temp_inc); ?> <div class="header_wrap"> <div class="options_wrap"> <div class="title"> <ul><li><?php echo vldext_lang("search","app_results"); ?></li></ul> </div> <div class="clear"></div> </div> </div> <?php if ( ( int ) $_obj['page_links'] == 1 ) { ?> <p>Welcome to our website</p> <?php } ?> <?php $_temp_inc = $TEMPLATE->output('message.tpl',0); include($_temp_inc); ?> <?php if ( ( int ) $_obj['hide_content'] != 1) { ?> <div class="outter page_search_results"> <div class="typemembers"> <?php if ( @$PREFS->conf['enable_saved_searches'] && @$SESSION->conf['can_save_searches'] ) { ?> <div class="dataitem single" id="div_save_search" style="display: none"> <div class="form"> <div class="entry" id="save_search_response"> <form name="form_save_search" id="form_save_search" action="" onsubmit="save_search();return false;" method="post"> <div class="fieldset"> <dl class="fieldset fieldgrid"> <dt><label for="field_search_save"><?php echo vldext_lang("search","save_search"); ?></label></dt> <dd><input name="search_save" type="text" class="text" id="field_search_save" style="width: 200px" value="" maxlength="128" /></dd> <dd class="submit report"> <input id="save_search_submit" class="submit" name="submit" value="<?php echo vldext_lang("search","submit"); ?>" type="submit" /> <div class="progress" id="save_search_progress"></div> <div class="clear"></div> </dd> </dl> <div class="clear"></div> </div> <input type="hidden" id="field_hash" name="hash" value="<?php echo isset($_obj['search_hash']) ? $_obj['search_hash'] : "{search_hash}"; ?>" /> </form> </div> </div> </div> <?php } ?> <div class="dataitem single" id="div_reorder" style="display: none"> <div class="form"> <form name="form_reorder" action="<?php echo isset($_obj['virtual_path']) ? $_obj['virtual_path'] : "{virtual_path}"; ?><?php echo isset($_obj['search_link']) ? $_obj['search_link'] : "{search_link}"; ?>" method="post"> <div class="fieldset"> <dl class="fieldset fieldgrid"> <dt><label for="field_orderby"><?php echo vldext_lang("search","order_by"); ?></label></dt> <dd><select class="select" name="orderby" id="field_orderby"><?php echo vldext_dropdownlist($_obj['orderby_box'],$_obj['search_orderby']); ?></select></dd> <dt><label for="field_direction"><?php echo vldext_lang("search","direction"); ?></label></dt> <dd><select class="select" name="direction" id="field_direction"><?php echo vldext_dropdownlist($_obj['direction_box'],$_obj['search_direction']); ?></select></dd> <dt><label for="field_display_type"><?php echo vldext_lang("search","display_type"); ?></label></dt> <dd><select class="select" name="display_type" id="field_display_type"><?php echo vldext_dropdownlist($_obj['displaytype_box'],$_obj['displaytype']); ?></select></dd> <dd class="submit"><input class="submit" name="submit" value="<?php echo vldext_lang("search","submit"); ?>" type="submit" /></dd> </dl> <div class="clear"></div> </div> </form> </div> </div> <?php if ( ( int ) $_obj['displaytype'] == 1) { ?> <div class="dataitem single gallerybox"> <?php if (!empty($_obj['search_profiles'])){ if (!is_array($_obj['search_profiles'])) $_obj['search_profiles']=array(array('search_profiles'=>$_obj['search_profiles'])); $_tmp_arr_keys=array_keys($_obj['search_profiles']); if ($_tmp_arr_keys[0]!='0') $_obj['search_profiles']=array(0=>$_obj['search_profiles']); $_stack[$_stack_cnt++]=$_obj; $_cnt['search_profiles']=count($_obj['search_profiles']); foreach ($_obj['search_profiles'] as $rowcnt=>$search_profiles) { $search_profiles['rowcnt']=$rowcnt; $search_profiles['rowpos']=$rowcnt+1; $search_profiles['rownum']=$rowcnt%2+1; $search_profiles['rowtotal']=$_cnt['search_profiles']; $search_profiles['rowfirst']=$rowcnt==0?1:0; $search_profiles['rowlast']=($rowcnt+1)==$_cnt['search_profiles']?1:0; $_obj=&$search_profiles; ?> <div class="image"> <?php $_temp_inc = $TEMPLATE->output('member_sections_picture.tpl',0); include($_temp_inc); ?> <ul><li><a href="<?php echo isset($_stack[0]['virtual_path']) ? $_stack[0]['virtual_path'] : "{virtual_path}"; ?><?php echo isset($_obj['member_profile_link']) ? $_obj['member_profile_link'] : "{member_profile_link}"; ?>"><?php echo vldext_trim($_obj['member_username'], ; ?>, <?php echo isset($_obj['profile_field_age_value_years']) ? $_obj['profile_field_age_value_years'] : "{profile_field_age_value_years}"; ?></a></li></ul> </div> <?php } $_obj=$_stack[--$_stack_cnt];} ?> <div class="clear"></div> </div> <div class="clear"></div> <?php } else { ?> <?php if (!empty($_obj['search_profiles'])){ if (!is_array($_obj['search_profiles'])) $_obj['search_profiles']=array(array('search_profiles'=>$_obj['search_profiles'])); $_tmp_arr_keys=array_keys($_obj['search_profiles']); if ($_tmp_arr_keys[0]!='0') $_obj['search_profiles']=array(0=>$_obj['search_profiles']); $_stack[$_stack_cnt++]=$_obj; $_cnt['search_profiles']=count($_obj['search_profiles']); foreach ($_obj['search_profiles'] as $rowcnt=>$search_profiles) { $search_profiles['rowcnt']=$rowcnt; $search_profiles['rowpos']=$rowcnt+1; $search_profiles['rownum']=$rowcnt%2+1; $search_profiles['rowtotal']=$_cnt['search_profiles']; $search_profiles['rowfirst']=$rowcnt==0?1:0; $search_profiles['rowlast']=($rowcnt+1)==$_cnt['search_profiles']?1:0; $_obj=&$search_profiles; ?> <div class="dataitem <?php echo vldext_ifelse($_obj['rownum'],"1","odd","even"); ?> <?php echo vldext_ifelse($_obj['rowlast'],"1","dataitemlast",""); ?>"> <table class="plain"> <tr> <td> <div class="image"> <?php $_temp_inc = $TEMPLATE->output('member_sections_picture.tpl',0); include($_temp_inc); ?> </div> </td> <td class="data"> <div class="datainfo"> <?php $_temp_inc = $TEMPLATE->output('member_sections_name.tpl',0); include($_temp_inc); ?> <dl class="datainfo"> <?php $_temp_inc = $TEMPLATE->output('member_sections_card.tpl',0); include($_temp_inc); ?> </dl> </div> </td> <td> <div class="actions"> <ul class="actions"> <?php $_temp_inc = $TEMPLATE->output('member_sections_quick_actions.tpl',0); include($_temp_inc); ?> </ul> </div> </td> </tr> <tr> <td colspan="3"> <div> <?php echo vldext_trim($_obj['profile_field_inmyownwords_value'],300); ?></div> </td> </tr> </table> </div> <?php } $_obj=$_stack[--$_stack_cnt];} ?> <?php } ?> </div> <div class="clear"></div> </div> <?php if ( ( int ) $_obj['total_pages'] > 1) { ?> <div class="footer_wrap"> <div class="footer"> <p><?php echo vldext_lang("search","page_numbers"); ?></p> <?php echo isset($_obj['page_links']) ? $_obj['page_links'] : "{page_links}"; ?> <div class="clear"></div> </div> </div> <div class="clear"></div> <?php } ?> <?php } ?> <?php $_temp_inc = $TEMPLATE->output('footer.tpl',0); include($_temp_inc); ?>
-
your cart should have it's on $key['quantity] that way when a item is added or removed it's as simple as $key['quantity] += 1; || -= 1; That will save you from having to loop your cart every time a item is added or removed just to get the total items in your cart. Think of it this way... cart items are unique so they need an array() of item(s), but things like total items, total price, etc... are not unique, so they only need a single $key => $value;
-
Use sessions, or just do a redirect with the date value in your url.
-
before your foreach() $s2 = ''; inside your foreach(), change to... ( missing concentration operator ('.') ) after $s2 .= $s2 .= '<li>' . '<span>' . date('j.n.Y',$ti['createdAt']) . '</span>' . ' - ' . $ti['text'] . '</li>';
-
Could you try this code... if I recall, curl 7.20.*, and 7.21.* has problems with CURLOPT_POST | CURLOPT_POSTFIELDS if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) { if( isset ( $_POST['g-recaptcha-response'] ) && ! empty ( $_POST['g-recaptcha-response'] ) ) { $key = 'my key'; $rip = $_SERVER['REMOTE_ADDR']; $captchaurl = 'https://www.google.com/recaptcha/api/siteverify?'; $captchaurl .= 'secret=' . $key . '&'; $captchaurl .= 'response=' . $_POST['g-recaptcha-response'] . '&'; $captchaurl .= 'ip=' . $rip; $curl_init = curl_init (); curl_setopt ( $curl_init, CURLOPT_URL, $captchaurl ); curl_setopt ( $curl_init, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $curl_init, CURLOPT_TIMEOUT, 5 ); curl_setopt ( $curl_init, CURLOPT_USERAGENT, 'PHP/reCAPTCHA' ); curl_setopt ( $curl_init, CURLOPT_SSL_VERIFYPEER, FALSE ); $response = curl_exec ( $curl_init ); if ( $response == FALSE ) { echo '<p>Curl Error: ' . curl_error ( $curl_init ); } else { $result = json_decode ( $response, TRUE ); echo 'Recaptha Result: '; var_dump ( $result['success'] ); } curl_close ( $curl_init ); } }
-
Help in Opencart sms notification to user
printf replied to navachaitanya's topic in PHP Coding Help
create a new method with your sms code in the class "ControllerAccountRegister extends Controller", then call that method right before... // your sms method call here... $this->sendSMS(); $this->response->redirect($this->url->link('account/success')); but I myself would turn it into an extension, that way I could control it from the admin panel... but how to do that goes beyond the scope of a scripting help forum. -
This looks like a PHP question, not a SQL question! Anyway, move the <table> out of the loop, and then just style your <tr> tag with a border-top or border-bottom. <td> <table class='commenttable'> <?php include '../Scripts/connection.php'; $sql = "SELECT id, name, email, subject, comment FROM comment"; $result = $connect->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo " <tr style=\"border-bottom: 1px solid #000;\"> <td class='id'> <u>Loyal Client ". $row["id"] . "</u>: </td> <td class='subject'> " . $row["subject"]. " </td> </tr> <tr> <td></td> <td class='comment' colspan='2'> " . $row["comment"]. " </td> </tr> "; } } else { echo " <tr> <td> No Comments </td> <tr> "; } ?> </table> </td>
-
There are many ways to do it, but I would just do all of it when you are building $page['content'], using some kind of join, that way you don't need to call up the database again, or use repetitive loops because your logic is BAD. But if you must do it the way you are doing it, create a function or call back function that draws out the (\d+) and then just replace {gallery:\d+} with your image paths... But use string functions, and sprintf() to do the replacement, as (40) simple string function calls uses less CPU(s) clocks than a single REGEX pattern call! example... <?php function getNumber ( $string, $p_start = '{gallery:', $p_end = '}' ) { if ( FALSE !== ( $start = strpos ( $string, $p_start ) ) && ( $end = strpos ( $string, $p_end, $start ) ) !== FALSE ) { return array ( substr ( $string, ( $start + strlen ( $p_start ) ), ( $end - ( $start + strlen ( $p_start ) ) ) ), substr ( $string, 0, $start ) . '<img src="%1$s" />' . substr ( $string, ( $end + 1 ) ) ); } return FALSE; } // string to sprintf on $string = '<h1>Title of the page</h1> {gallery:19} <p>Other informations...</p>'; // data to insert into string $from_db = 'admin/uploaded/someimg.jpg'; if ( ( $out = getNumber ( $string ) ) !== FALSE ) { echo sprintf ( $out[1], $from_db ); } ?> note... $out[0] = contains the id that you would query the database with
-
trying to join Members table and members pics table?!
printf replied to jarv's topic in PHP Coding Help
LEFT OUTER JOIN -
Don't use single or double quotes in your aggregate (GROUP BY) functions MIN(SALEPRICE) // correct, mysql interprets as column name MIN('SALEPRICE') // not correct, mysql interprets as a literal value SALEPRICE
-
I guess you you didn't understand what I meant, so here is an example... SELECT horse, SUM(IF(win>0, 1, 0)) AS total FROM ((SELECT `Horse Number` AS horse, `Win $` AS win FROM `races`.`2009`) UNION ALL (SELECT `Horse Number` AS horse, `Win $` AS win FROM `races`.`2010`)) AS junk GROUP BY horse ORDER BY SUM(win); change all the SUM(???) to COUNT(win) if your table isn't the way I am thinking it is!
-
Instead of UNION, UNION ALL
-
Use a regex with a whole word boundary so you don't have to worry about the separator *,*. We use the whole word boundary so user_id 24, 14, etc won't match user_id equals 4 $user_id = 4; // would return rows 1, 2 // you can match multiple user_id(s) at the same time. // $user_id = '5|7'; // would return rows 2,3 $query = "SELECT * FROM yourTable WHERE users REGEXP '[[:<:]]" . $user_id . "[[:>:]]'";
-
You access variables by there SUPER GLOBAL names, $_POST['hammer'], $_GET['hammer'], $_REQUEST['hammer'], or you can just use extract($_POST). extract($_GET). extract($_REQUEST). Then you can use the varibles as you use to. But I wouldn't recommend you do that, because it can open your scripts to some security problems! <?php extract($_REQUEST); if ($hammer): ?> blah blah html for hammers.. <?php elseif ($nails): ?> blah blah html for nails ... <?php endif; ?>
-
A query should a function within a database class, not a class it's self. Naming conversions are just as important coding logic. What I mean... If I see someone name a database class dbQuery or some other name that should purely only be a function within database class I tend to know that the coding logic will not be very sound. Sure everyone has their own coding style, but naming classes with names that will only confuse someone is simply illogical. A QUERY, QUERY_ERROR, etc, are logically member functions of a database class, not classes their self!
-
Use Archive_Tar class from the Pear Repository.. Then do something like this... $upload_file = 'upload_file.gz'; $temp = 'temp.tar'; // inflate and save the tar archive file_put_contents ( $temp, gzinflate ( $upload_file ) ); // require the tar archive class require ( 'tar.php' ); // create the tar file $tar = new Archive_Tar ( $temp ); // array to hold all the file names in the tar archive (for extracting) $list = array (); // array to hold all the files attributes in the tar archive (for whatever purpose) $data = array (); // temp directory where to put all the files that are in the tar archive $tmp = '/tmp'; // remove part of the memorized file names (read tar_archive docs to understand this!) $remove = ''; // read tar file contents if ( ( $files = $tar->listContent () ) != 0 ) { foreach ( $files as $file ) { $list[] = $file['filename']; $data[] = array ( $tmp . '/' . $file['filename'], $file['size'] . ' bytes', date ( 'm-d-Y', $file['mtime'] ) ); } // extract all files in the tar archive $tar->extractList ( $list, $tmp, $remove ) or die ( 'Could not extract files!' ); // now do stuff with all your files foreach ( $data AS $item ) { $out = fopen ( $item[0], 'rb' ); // do whatever fclose ( $out ); } }
-
Zlib can only compress a single file. It doesn't have the ability to pack / unpack multiple archives. It sounds like the archives you are working with are .tar'ed first then zlib'ed which is possible because .tar allows for multiple uncompressed archives. But without seeing the file that is just a guess. But again Zlib it's self cannot manage or manipulate multiple archives.