12.07.2023
1.1K
The PHP strpos function is used to find a substring in a given string. It returns the numeric value of the first occurrence of the specified substring.
Syntax for using strpos
The PHP strpos function is used as follows:
$position = strpos($given_string, $search_string);
Note: When searching using the strpos function, case is sensitive. So searching for the keywords “Test” and “test” will give different results.
Position counting starts from 0, not 1.
Using demo versions, I will demonstrate the use of this function to search for a given substring and a user-entered value.
A simple example of using the strpos function
Check out the following example, where I used lookup values to demonstrate how the PHP strpos function works:
View online demo and code
PHP code:
"; echo " The given substr found at: $position"; ) ?>
strpos PHP example:
The string contains the search term: ‘strpos’! The given substring found at: 10
Example of using strpos to search for a user-entered term
This method may be useful in certain scenarios. For example, when a form does not allow certain words to be entered.
In addition, you can check whether the word specified by the user for search is contained in the source string. Based on this, you can output certain results in the form of an answer.
In this demo, the user can enter a term into a text field. Once the button is clicked, the strpos function is run to check if the original string contains a substring. The following message will be displayed on the screen:
For the demo I used the following source line:
$source_string = "In this demo, I am using a user entered search term to check if string contains search term or not by using strpos!";
Try entering different letters or words to search to see if the function returns false . Also, try entering terms in capital or small letters to see the difference.
The following PHP strpos utf 8 example was used for this:
"; if ($posistion === false) ( echo "The source string does not contain the: "$search_term"!"; ) else ( echo "The string contains the search term: "$search_term"!"; echo " The given substring found at: $position"; ) echo "
";
}
?>
You can also look at the strpos PHP markup example:
The full version can be seen in the source code of the demo page.
In addition, you can use a database as a source to create a search system on your website.
Case-insensitive search using stripos function
As mentioned, the PHP strpos function is case sensitive. To search for strings regardless of case, use the PHP stripos function.
The syntax is almost the same as for strpos:
$position = stripos($given_string, $search_string);
Now I'll show you how stripos works.
Example of using the stripos function
In this demo, the search source is the following string:
$source_string = "This is a stripos Tutorial which is used to search strings. It tells whether a given string contains a search string or not!";
Search term: $search_term = 'tutorial';
They complement each other. If you study them together, everything becomes clearer and more visual.
Sixteen psychological types are divided into fours, the so-called quadras. Those in the same quadra understand each other perfectly. Each quadra has its own characteristics of behavior, its own worldview, attitude to work, sense of humor, and finally - everything that can be called the “spirit of the quadra.”
It is interesting that when types from different quadra meet, they are unfamiliar with the characteristics of their partner’s sexual behavior.
Members of the quadra are the most sexually compatible partners. Let's take a closer look at sexual behavior in each quadra.
Second quadra:
"Hamlet", "Gorky", "Zhukov" and "Yesenin".
In the second quadra, the nature of sexual caresses is completely different. Here they do not like light stroking, but strive for an intense effect on the skin, which manifests itself in strong hugs when partners squeeze and squeeze each other. Sensory types "Macedonsky" (Zhukov) and "Gorky" are very jealous: the mere thought of betrayal can poison their lives. Shakespeare's Othello ("Gorky") kills Desdemona. It is characteristic that at first he strangled her - Shakespeare (Hamlet) showed this not by chance. We can give examples from life: a husband (“Gorky”) and wife (“Hamlet”) live in a hostel. Since the wife is a sociable extrovert, her husband is very often jealous of her neighbors. Moreover, each time the scene is played out almost according to Shakespeare: “Who were you with?” - asks “Gorky” and takes “Hamlet” by the neck with his hands. She screams and he lets go of her in fear.
As for “Makedonsky” (Zhukov), in moments of intimacy he can give clear, confident commands to “Yesenin” - it is not without reason that the second pseudonym of this type is “Marshal”. The mirror relationship between “Makedonsky” and “Gorky” is quite complex: in order to adapt to a partner, “Makedonsky” needs to constantly control himself and restrain himself. This tires him very much, but if he doesn’t do this, he will neuroticize “Gorky” with his sensory abilities, which are absent in “Hamlet.” From Hamlet, Gorky expects intense dramatic feelings and support for his sensory initiatives. At the same time, partners can take the most incredible poses.
It is interesting that when types from different quadra meet, they are unfamiliar with the behavior of their partner. So, the “Dreiser” woman was very surprised when the “Yesenin” man squeezed her tightly in his arms - she had to “retrain” him.
Third quadra:
"Napoleon", "Balzac", "Dreiser" and "Jack London".
The sexual program of the Gamma quadra is very dynamic and often characterizes the acrobatic behavior of partners. In the “Caesar” - “Balzac” dyad, the initiative is usually always in the hands of “Caesar” (Napoleon), who sensory controls the partner. “Balzac” obeys, even if you just resolutely take him by the hand. He says: “If you take me and lead me, then I will immediately go and will not resist, I will succumb to the control of my partner.”
As for the “Dreiser” - “Jack London” dyad, it is characterized by frequent changes in partners’ positions and high intensity of feelings, as well as a large number of sexual intercourse (for example, over several days) followed by a long rest. At the same time, if “Caesar” “cools down” very quickly after sexual intercourse, then “Dreiser” may require one or two hours of caresses and stroking of the partner. The mirror relationship between “Caesar” and “Dreiser” is similar to the relationship between “Macedonsky” and “Gorky”: “Dreiser” is also quite jealous.
In this regard, it is interesting to compare the intimate relationships of “Dumas” and “Caesar”. The relationship between them is complete opposites. This can lead to the fact that partners (especially the introvert) quickly grow cold towards each other, and a truly complete sensory and emotional repayment occurs.
But between “Don Quixote” and “Balzac”, “Yesenin” and “Huxley” such suppression occurs less frequently; their sensory functions are in the subconscious.
Playful behavior, laughter, pinching a partner, etc. includes the quadra "Delta" sexual program.
"Stirlitz" shows more energy, but less creativity to "swing up" the shy "Dostoyevsky", and is less restrained compared to "Gaben". “Gabin” himself, saving energy, shows more creativity with his dual “Huxley”; they both look at it as high art. "Huxley" women are characterized by wriggling, flirtatious and "cat-like" movements. External stimuli - films, literature, music - have a very strong impact.
Huxley's weak point is pity: a partner can achieve success by talking about his suffering. In this situation, “Huxley” becomes tender, feels an urgent need to bring relief to at least someone;
By the way, another pseudonym of “Huxley” is “Don Juan”: he successfully courtes a woman, but at the last moment he can shy away from intimacy. Only his dual "Gaben" or activator "Stirlitz" can take the initiative into their own hands.
The topic “psychotypes in love and sex” on our website is devoted to:
Determine the type of sexual constitution. A person is distinguished - strong, average and weak.
Determine your sexualities: permissiveness, fulfillment, neuroticism, satisfaction\dissatisfaction, disappointment, shyness, chastity, aversion to sex, excitability, libido.
Tendency to impersonal sex, pornography, physical sex, aggressive sex.
Sergey and Irina Beletsky “How to apply socionics to fulfill your desires. 7 secret steps"
Lyubov Beskova, Elena Udalova “The path to a man’s heart and... back”
Anatoly Grechinsky, Tatyana Pedan “Find harmony in life. Socionics about man"
Victor Gulenko “Description of socionic types and intertype relationships”
Victor Gulenko “Criteria of reciprocity”
Victor Gulenko “Life Scenarios”
Otto Kroeger, Janet Tuson “16 roads of love. How 16 Personality Types Determine Your Possibilities in Love"
Otto Kroeger, Janet Tuson “Types of people. 16 Personality Types That Shape How We Live, Work, and Love"
Tatiana Prokofieva “Socionics. Algebra and geometry of human relationships"
Yuri Simonov, Alexander Nemirovsky “How to look for a life partner”
Vera Stratievskaya “How to make sure we don’t part”
Vladimir Stukas, Ellina Untilova “Psychological typology that works”
Ekaterina Filatova “The art of understanding yourself and others”