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);
}
Related
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
How do i assign the successive duplicate values of a string in a single offset of an array In PHP. For example FFF2AA
In array it should be
0=>FFF
1=>2
2=AA
In array format
This post Count consecutive occurence of specific, identical characters in a string - PHP gives you almost your perfect answer. you just have tu use '*' instead of '+' in the regex if you want to take into accounts 1 character strings (like the '2' above).
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
EDIT: I solved it. Just need to use "MongoDB\BSON\Regex".
I'm storing books as documents in MongoDB, with the individual pages stored as strings in an array. I'm trying to implement a search page that can take a string and return all documents that contain it. Can this be done directly with a MongoDB query called using PHP (i.e searching for a substring within the string arrays)?
I'm using MongoDB\Driver ( http://php.net/manual/en/book.mongodb.php ) because it was the only option that worked on my machine, and I couldn't find detailed documentation or tutorials for this particular driver. Can anyone help?
Something like
db.table.find({"bookTextField": /.*(the string).*/})
EDIT: Of course, replace table by the table name and bookTextField by the field of the table containing the text
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
There are two arrays. It is necessary to display a list from the first array on the page, in which the elements of the second array will be highlighted, for example with a color. Probably it is necessary to read one array in a loop and compare, for example preg_match with the second array and if there is a coincidence - to allocate. Does anyone have a more beautiful solution?
There is an array_intersect function that does pretty much what you need. If you want to compare the elements using regular expressions, try preg_grep, but you will need to prepare the pattern first.
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)
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';
}