0 Users appreciate this thread.
[PHP] Partial String Detection
GuitarBoy (2014-07-05 23:30:25)You could also use strpos($haystack,$needle int $offset=0).
if(strpos("wafflez r good","wafflez"
#code to execute here
}
I'd use strpos in lieu of preg_match in a simple case like this.
http://m.ajango.org - Ajango
New social networking website coming this year! Check for updates frequently!
Ajango Forum Thread
New social networking website coming this year! Check for updates frequently!
Ajango Forum Thread
CoolApps (2014-07-06 00:57:41)Interesting, I haven't been looking into strpos() much since I don't often need to use word detection and there's other functions which does the job as well but in a more simple way.
2014-07-06 08:02:04
Newer account: NodePoint
(Capt.)Orb (2014-07-08 22:21:20)Interesting, I love how you "randomly" selected that number.
Aviation fact: The a380 is the largest commerical aircraft in service!
Go to Splashiverse! Splashiverse
Go to Splashiverse! Splashiverse
GuitarBoy (2014-07-09 23:37:27)Not to get off topic but in computer science you learn that there is no such thing as a "random" value. It all depends on the electrons flowing through the processor at a given moment, and particle movement is pretty random, but still has rhyme and reason due to physics.
http://m.ajango.org - Ajango
New social networking website coming this year! Check for updates frequently!
Ajango Forum Thread
New social networking website coming this year! Check for updates frequently!
Ajango Forum Thread
CoolApps (2014-07-11 16:31:12)It's called random because it comes up with different integers every time.
Newer account: NodePoint
Log in to submit a comment
Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)
New registered users today: 7
Newest registered user: ElegantVulpes

Because I was bored, I've made a simple script with a function which I've never used before.
Link to the working example: http://caftp.pcsat.tv/testfiles/gen69.php
Here's the code:
<?php
$test = str_shuffle('1234567890'
$test2 = preg_match('/69/',$test);
if ($test2 == '1'
echo 'Found 69!
}
else {
echo 'No 69 was found.
echo '<br>';
echo 'Refresh again to try to find it.';
}
echo '<br>';
echo '<br>';
echo 'Generated String: '.$test;
?>
I'm of course using variables to make this easier and clean.
----------------------
str_shuffle() Does what it says on the tin (str being string), it shuffles the string, this was the function which I was talking about at first.
preg_match() then checks that shuffled string for "69" (I was that bored ok!), this has multiple return values, 1 or TRUE if found or 0 or FALSE if not found.
I then used the IF ELSE statement to check if preg_match returns "1" (meaning it found "69" ) and if it does, it echo's the text saying that it was found, else echo the text if it doesn't return "1".
I've then echoed the actual shuffled string directly.
---------------------
You could say that it's simple (if you've been coding using PHP for a while).
---------------------
If you see emoticons in the code, that was done in the webpage so that was intended.
Be sure to share your simple creations!
2014-07-06 01:26:07