Jump to content

phppup

Members
  • Posts

    644
  • Joined

  • Last visited

Posts posted by phppup

  1. I recently had occasion to use

    <input type="color">

    It seemed like a nice idea until I viewed it on an IE 11 browser.

    Since IE11 does not support the tag, it provided a text input instead of the COLOR input functionality.

    The input field CAN be used as a substitute as long as acceptable color NAMES are typed, but the field size is much wider than it would be as type=color in a newer browser (and that alters the page layout).

    Since a user COULD be using an older browser, it seems that controlling the WIDTH of the input should solve that problem.

    The real issue is a way to create a script to determine whether the setting adjustment is even necessary.

    Something like

    if (input [type='color'] != a cute button with a color graphic) {
      input.width = 10px;
      }

    Insightful responses, please.

    PS: While on the topic, does anyone happen to know the DEFAULT settings for input="text" with regard to the height, width, font size, font family of the field?

     

     

     

  2. @Barand Thanks.

    But this solution looks like it will only identify one (the first) instance of cat.

    Suppose the file contained assorted sentences of "Funny things my pet does."

    While each paragraph will contain a sentence "My [type of pet] does this silly thing [period]." not every paragraph will contain "cat" because a "cat" is not the only pet.

     

  3. I see how substr_count works.

    But I want to add to it  with

    echo "Occurrence $cnt says" . $blahblahblah

    Is there a built-in function to use for this? Or do I need to create a loop like

    if( i=0; i<$cnt; i++){
      //if this position was already used then continue
      //otherwise, i assume i will get there same data i times
                   
                     }

    to get a complete listing?

  4. @ginerjm I think I became intrigued with querySelectorAll.

    Having said that, what is the best way to move through the data (most likely as a string) to achieve an accumulation of like instances.

    eg: find all instances of "cat"

    Do I count the line that the first instance occurred on and create a clause to search for an instance where $line > $the_previous ?

     

  5. Some good information that I will have to try out.

    Since I am already somewhat invested in the JavaScript method, it will be interesting to put them side by side to see if I get identical results.

    Since I need to"read" the file from the server, it would be much cleaner to keep this completely within a PHP format.

    Thanks for the help.

  6. @ginerjm I am not a code by either profession or training. More like an overzealous hobbyist.

    And while I understand your example, it's not something that I would have thought of myself, nor have I seen examples like it in my search engine queries.

    So, thanks.

    Now the question is, how (if possible) would I avoid JavaScript and have PHP pull results from those resulting lines in your example?

    My current thought process is to use document.querySelector in order to loop through and pull data to use on a new script.

     

    @Barand Admittedly, this is something that came up AFTER implementation of other ideas, so it may be a backwards approach.

    But for now, it's (hopefully) easier than re-structuring my other files. 

    So, getting info that already exists and re-using it in this manner just might work.

     

     

  7. I'm trying to gain access to a file for the purpose of extracting a portion of it for use with JavaScript.

    If there's an advisable methodology that can be shared, that would be GREAT.

    The best that I've come up with is to use readfile("sample.php"); to gain access to the data.

    However, I then want to run a JavaScript on this data.

    Is there a recommended way to accomplish this?

    The only way I can think of is to move the data into a variable, but my effort has a bug.

     

    echo readfile("sample.php");  //provides a viable result
    
    //but then...
    $my_variable = readfile("sample.php");
    
    echo $my_variable;          //provides a number (I have not determined what that number represents... perhaps a line or character count??)

     

    //Note: print_r($my_variable)  provides same result

     

    How can I achieve  a successful result and transfer the data so that JavaScript can affect it?

  8. Copied a wrong line.

    But still...

    fruits = ["apple", "orange", "cherry"];
    
    for (x = 0; x< fruits.length; x++){
      
    document.getElementById("demo").innerHTML = fruits[x];
      
      }

    What would get this working?

    Would for each be any better?

     

  9. My code is a mess from various attempts at a simple task (it is embarrassing). And also frustrating (especially since my searching hasn't found a solution, or a more important explanation of WHY a method works).

    I want to have my stay contents displayed in a specific HTML container.

     

    fruits = ["apple", "orange", "cherry"];
    
    x = document.getElementById("myList").innerHTML;
    
    for (x = 0; x< fruits. length; x++){
      
    document.getElementById("demo").innerHTML = x;
      
      }

    I need a solution. And would appreciate comments for educational understanding.

     

    Thanks.

  10. Well, I'm not sure (because the whole point was to minimize code lines... LOL).

    And this was just a personal effort to see where it might lead me.

    I wouldn't have thought of using INCLUDES and I don't do well when I lose track of my (visible) code.

    The funny thing about this little project is that the"variables" are probably the most "constant" piece of the puzzle.

    That's why I thought FUNCTIONS would be a good step.

    In essence, some might be considered late after 5 minutes, others are 10. Some after 30, others 120.  Hence, a different (short) function for each scenario. 

    Essentially, the messages are the same: Your late, your very late, see your supervisor, go home fool, etc. regardless of "group."

    I'm still considering my options, and the other factors that might guide me.

    No hurry for this one.

  11. @ginerjmYes, and I appreciate your input.

    But the solution means that I have to include the array in every redundancy of similar functions that will use those variables.

    Without using functions at all,I can list the variables once and write straight code.

    Either way, something will be repeated, so I have to re-evaluate.

    At least NOW, I can make an informed decision.

  12. Just did more reading and I'll have to review my implementation.

    It seems that my attept to reduce (already short) code repetition will result in an increase of duplicated variable lists.

    But the effort was a learning experience.

    Thanks for the responses.

  13. I think I'd prefer to pass them as arguments.

    Can you save me the trouble of sorting through bad information from a search engine?

    (I've seen some info about using an ampersand, but it wasn't very clear)

    Are you saying that if I include the variables within the { } of the function that it will work?  I tried that earlier but it failed.

    If these variables will be used as reference to other functions, Is there a Best Practices path to proceed on?  Will wrapping the variables in a function of their own to be called inside of this function provide the desired result?

  14. While working with some code I wrote this and it works

    <?
    
    if(isset($_POST['submit'])) {
    $greeting = "Good morning";
    $late = "You are late";
    
    if($_POST['time'] > 0) {
    echo $greeting;
            }
    
    if($_POST['time'] > 5) {
    echo $late;
            }
      }
    
    ?>

    Then I decided to modify it into a function (which would be preferable for expanding the code's usefulness)

    That's when my problems began.

    What do I need to do so that the function works as well as the straight code?

    
    <?
    
    $greeting = "Good morning";
    $late = "You are late";
    
    function greet(){
    if($_POST['time'] > 0) {
    echo $greeting;
            }
    
    if($_POST['time'] > 5) {
    echo $late;
            }
        }
    
    if(isset($_POST['submit'])) {
    greet();
    }
    
    ?>

    I thought I'd ask the experts.

    Thanks.

  15. It seemed simple when I thought of it, but multiple variations are NOT producing the result I imagined.

    Essentially, I have a single table that I want centered on a webpage, with a second table to the right.

    <center><div>
      content 
    </div> </center>
    
    <div style="float: right;">
      content
     </div>

    I enclosed the tables in <div> tags but my results did not improve.

    I do not want two side by side tables that are centered. I am trying to have one centered table with a second to its right.

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