Jump to content

Zane

Administrators
  • Posts

    4,362
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zane

  1. It's pretty simple really.

    You just follow this migration guide that's provided in the PHP.net manual
    http://php.net/manual/en/migration70.php

    Generally though, unless you've created something so complicated that it's way above average in its composition, it'll be a pretty smooth transition. Mainly, for your most basic PHP7 compatibility check, you'll just make a list of all the functions that you are using in your code, and check each one against what they show as compatible in the manual.
    For instance, let's look at the isset() function. The manual says at the top that it's available with PPHP 4, PHP 5, and PHP 7.

    The most important thing you need to make sure of is that you're aware of any changes to functions.

     

    Regardless, PHP will give you the error messages you'll need to ask a proper and less broad question.

  2. You could set a session/cookie variable value with a boolean. Like, iniitated_payment. Set to true on click of successful submission (no form errors) and only allow logic to occur when that cookie's value is false. If your payment engine throws an error, then set it back the cookie back to false... or whatever. Several things you could do; it's your UX.

  3. A quick fix would be to just strip everything before the ?

     

    Add this snippet of code, just above this line

    // Strip out the query params section
    $source = explode('?', $node->display_src)[0]);
    $rss_feed .= '<description><![CDATA[<img src="'.$source.'" />]]></description><guid>https://instagram.com/p/'.$node->code.'/</guid></item>';
    
  4. There's really no reason to grab all the files with PHP and then loop through them and do exclusions with PHP again.  Just add your restrictions to the glob() call, and then you'll have only your image files.

    glob($root . $path . "*.{jpg,png,gif}", GLOB_BRACE);

    And yea, absolutely, get PHP 5.6+.  Why live in the past?

     

    Looking in the manual, there doesn't appear to even be a v5.3.3, but 5.3.29 came out in 14 Aug 2014, while PHP 5.6.22 came out in 26 May 2016

  5. Another way of adding your variables to your strings is by using { } curly braces.

    Note: you can only do this when your string is enclosed with double quotes " because content between single quotes doesn't get parsed.

    echo "<input type='hidden' name='channel' value='{$_SESSION['channel_id']}' />";
  6. What will you do with duplicate ip numbers? Kind of hard to prevent that with a text file as a database.

     

    Not necessarily.  One could use a combination of the file() function and in_array() function to prevent duplicates.

     
    // Completely untested!!
     
    # get the submitters IP address
    $remote_ip = getenv(REMOTE_ADDR). "\r\n";
    $filename = "inbritain-ip-file.txt";
    $theFile = file($filename);
     
    $fileRef = fopen($filename) or die("Unable to open file!");
     
    foreach($theFile as $ip) {
        if( !in_array($remote_ip, $theFile) ) fwrite($fileRef, $remote_ip);
    }
    fclose($fileRef);
    
  7. Change this line

    fwrite($ip_file, $remote_ip . "\r\n");

    Or change this line

    $remote_ip = getenv(REMOTE_ADDR). "\r\n";

    The \r represents a carriage return (CR), while the \n represents an actual new line, or line feed (LF).

     

    This also means, though, that you will have a hanging/straggling newline at the bottom of your file.

  8. If you just trying to see if there are at least 2 digits, then temporarily strip all the non-numeric characters and count what is left.

    $example = '5teeth4';
    function atLeast2Numbers($e) {
        return ( strlen( preg_replace("/[^0-9,.]/", "", $e) ) >= 2); // Has at least two digits.
    }
    
    var_dump( atLeast2Numbers('fail5');      //false
    var_dump( atLeast2Numbers('pass5and6');  //true
  9. I would just pass it as reference, but that's just me.

    function changeKeyName (&$arr, $from, $to) {
         foreach($arr as &$k=>$val) $k = $k == $from ? $k = $to : $k;
    }
    
    $arr1 = ['abc'=>'one','def'=>'two','abc'=>'three'];
    
    changeKeyName($arr1, "abc", "xyz");
    

    Note: This is untested.

  10. It's because you're calling the tab() function on an anchor link that is not in your .tabbed-area

     
    I'm assuming also that you're wanting these links to trigger clicking on the real tabs, and in order to target your tabs, you'll have to give them IDs.

     

    So for your 4th tab, for instance.  Give it an ID of say, "step4" because these tabs are each unique to the page

    <a href="#tab4" id="step4">Your Acceptance</a>

    Then, for your links inside #tab1, first off, get rid of the hrefs, and replace them with a data attribute like data-target='step4', and also give them a class so you can target them with jQuery and use data-target to trigger a click on the appropriate tab.

    <a data-target="step2" class="tab1-anchor">One year before</a>

    Now that you have this, you can trigger a click on the step4 tab with this jQuery

    jQuery(function($){
        $("a.tab1-anchor").click(function(e){
             e.preventDefault();
             var theTab = "#" + $(this).data('target');
             $(theTab).trigger('click');
        });
    });

    There's possibly other better ways of accomplishing this, but this is the first thing that came to mind.  

     

    I feel like this solution of mine is more of a hack than it is the " proper" way to handle this.  Kicken's fiddle, I notice, works just fine without my hack.. So now I'm a bit unsure why things aren't working for you..  :shrug:

  11. Yeah, I suppose the word "troll" wasn't the best word to use (a bit harsh), I'll apologize for that.

     

    I do agree though that teaching best practices is a great thing to be doing, and leading people away from sub-par tutorials.  But, my point was that benanamen only ever mentioned obsolete code, never provided any relevant links,  nor provided any example code or anything other than just saying, It's obsolete, it ain't 1337.  Doing that is no different than the OP providing very vague information like "It doesn't work."  Lead by example, make an effort to explain that:

    $connection = mysql_connect("localhost", "username", "password");
    mysql_select_db('myDatabase');

    can be upgraded and consolidated to just

    $connection = mysqli_connect("localhost", "username", "password", "myDatabase")';

    Things like, what a prepared statement looks like, why is it better, yada yada.  There is always the short and simple solution to RTFM, but I'd say that message is mainly warranted to users that repeatedly don't read the manual and continue to say "it doesn't work, why?"  And perhaps this could be one of those cases.  Anyway, this is way off topic and I probably shouldn't have drank all of those beers before posting that reply  :intoxicated:

     

    I know that I, myself, didn't provide any help in this topic, but I did make sure to ask questions that we would need to know.  Regardless, I'm just rambling now.  :keep_quiet:

  12. Benanamen, if you're just here to troll and not offer any help, then.... you know, move along.  You can preach best practices until you're blue in the face, but it's not "help."  Just as you pointed out yourself

     

    Experience shows that once they get their old code working they never convert it later.

     

    So what? We're not here to spoon-feed and shove best practices down our community members' throats.  The basis of PHPFreaks is to allow someone with barely any knowledge of PHP (or web dev related things) to gain a firm grasp of it.  If the user decides to continue using legacy code, then so be it.  It's not like we're going to be held accountable, and even if someone attempted to do that, this is a volunteer based forum.  Let them use their old code.  In the long run, it means the user will return asking why XYZ isn't doing ABC, and someone will point out that the culprit is a line of legacy code, a legacy function.  Ultimately, the main goal is to have the users be able to learn how to expand on their questions and provide just the right amount of information for someone to help them effectively.  In due time, assuming the user pursues learning PHP, they will eventually see the error in their legacy methods and realize that the only fix is to be up-to-date.

     

    PHP7 is very young at this point, compared to PHP 5.6, which most people have been using for a long while.  Although it would be an awesome feeling to know that you helped someone create an innovative idea using the most up-to-date methods, it's not something to expect of our members.

    Just my 2 cents. ;).

  13. No reason to undermine yourself, Muddy_Funster.

     

    At one point in time, while we were on SMF, one of our staff created a bbcode mod for creating links to user accounts based on their username, but I don't think the idea ever surfaced about notifying the member of it.  It's a decent idea, but most definitely not a high priority thing, hardly even a low priority, but we do appreciate the suggestion!  I encourage anyone to post any and all suggestions they may have, in this forum in particular, because that's what this forum is here for.... and if it wasn't made clear already, by "this forum" I mean "PHPFreaks.com Questions, Comments, & Suggestions"

    • Like 1
×
×
  • 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.