Produce text on random page visit/refresh [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Maybe PHP isn't enough here (JavaScript?), but my aim is this:
I want a bit of HTML to show on a page at random, with a chance value I can adjust (1 in 10000, 1 in 1000, etc.) The end result should be after so many refreshes/visits to the page, the HTML will show; my hope is the user will feel it's a random occurrence.
Honestly, I couldn't even articulate this query to Google or StackOverflow or any site to produce a response even close to my desires. I'm also still a novice in PHP, so it didn't help the search.

Just create a random number.
$randomNumber = mt_rand(0, 100);
if ($randomNumber === 0) {
echo 'This will be echoed on average once every 100 times';
}

Related

How can I make a counter from 1 to 100 with PHP? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 10 months ago.
Improve this question
Hello friends, how can I add a counter that will count from 1 to 100 and then count from 1 to 100 again after a few minutes? It will be with PHP.
Here is a way to count until 100 in PHP but please make sure you choose your tags right, your question is currently marked as a javascript
question
I know it is related to javascript but your problem doesn't include even a piece of javascript
<?php
while (1){
for ($x = 0; $x <= 100; $x++) {
echo "The number is: $x <br>";
sleep(1);
}
}
?>
I would strongly suggest CRON JOBS for periodic script execution.
But it looks like some school or maybe even for fun task.
So the Answer from #Ramsey above should be sufficient.
(dont forget to kill the infinite process created by while (1))

Truncate String After 2 Sentences in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 12 months ago.
Improve this question
I have dynamic data that is pulled from the database.
Something like the following
$aychFour="From the start, community-minded business. Throughout our
25-year history in ABC, we have continually ways to give back.
We with local charities, involvement in numerous activities &
seasonal, as well as hosting in-store events so our guests can also.";
Since I am not sure about the contents of $aychFour, is it possible to find second period(.) in the string and truncate anything after that?
The explode() function can be usefull. You can divide the string in a array with $res=explode(".",$aychFour) and rebuild the string from the array given.
if(count($res)>1){
$aychFour=$res[0].".".$res[1].".";
}
Another approach is to search the second dot with strpos (or a regular expression).
$pos = strpos($aychFour, '.', strpos($aychFour, '.') + 1);
if($pos > 1){
$aychFour=substr($aychFour,0,$pos+1);
}

IF a URL contains a date in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a web site to analyze Instagram account and create report, and there's a function to display report for a particular dates range.
If I have date selected, then URL become ${base_url}/${date_start}/${date_end} , i.e.:
https://www.example.com/report/account-name/2020-02-01/2020-03-31
I want show historical data only to my premium users, so I need a way to check if URLs contain the value
/${date_start}/${date_end}
If "YES", then I'll show a notice to invite users to upgrade their plan.
I only miss the code to check IF URL contain /${date_start}/${date_end}
How to do that?
ps: dates is always wrotten like YYYY-MM-DD , so this should make thing easier, I suppose.
that is a regular expression you are looking for
if (preg_match('/\/\d\d\d\d-[01]?\d-[0-3]?\d\/\d\d\d\d-[01]?\d-[0-3]?\d/',$_SERVER['REQUEST_URI'])) {
echo 'dates found';
} else {
echo 'dates not found';
}

Generate all combinations of string in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to generate all possible combinations of a string using PHP. I've searched this site for a while trying to find the right algorithm but I can't seem to find the correct one. To be more specific if i input the string "hi", I want it to return "hi", "ih", "h", "i". But I don't want it to reuse the same characters multiple times. So I wouldn't want "hh" and "ii". Is there an algorithm for this? Thanks!
Dont take this for production:
$string = implode('',array_unique(str_split('helpa')));
$i=0;
while($i++<50000){
$coll[substr(str_shuffle($string),0,mt_rand(1,strlen($string)))]=true;
}
ksort($coll);
print '<pre>';
print_r(array_keys($coll));
Here you can test what you want to get.
In 10000 iteration i was getting 325 combinations from a 5 length string
(what seems all possible combinations)

PHP hide or cut part of image by unwanted text or sign on the picture [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How to hide or cut or blur for example car numbers on image?
so if i have thousand of image with cars like this
and i want to get something like this
So in which direction i should work to do this thing? There are default tools for this?
What you need is a face detection tool. For PHP, I know this script:
https://github.com/mauricesvay/php-facedetection
(Here is the detailed usage: http://www.codediesel.com/algorithms/face-detection-in-images-using-php/)
Just for fun, take a look in Google's Algorithm for Maps License Plate Blur tool:
http://static.googleusercontent.com/media/research.google.com/pt-BR//archive/papers/cbprivacy_iccv09.pdf

Categories