Questions tagged [strstr]

A function that searches a string in another string.

A function that searches a string in another string.

Examples

php
$email  = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // prints @example.com

(Example taken from php.net)

Resources

363 questions
0
votes
1 answer

Don't understand why strstr function is returning non-NULL value

I'm trying to write a simplified version of grep. It worked for most of the cases off the top of my head, but when I pass argument of "test" (ie "./grep test" in shell) and std input of …
user1953794
  • 27
  • 1
  • 7
0
votes
0 answers

Warning: strstr(): Empty needle in /home1/.........l/wp-content/plugins/events-manager/em-posts.php on line 257

I was working on event manager plugin and I made some changes which resulted to below error ! Warning: strstr(): Empty needle in /home1/....../public_html/wp-content/plugins/events-manager/em-posts.php on line 257 Warning: Cannot modify header…
0
votes
1 answer

strstr with strpos not working (PHP)

I am trying to trim the end of my URL after certain characters. I have my URL in a SESSION variable. if(strpos($_SESSION['LP'],'ordrer')) { $Order1 = $_SESSION['LP']; $Order2 = strpos($Order1, "ordrer"); …
0
votes
4 answers

strstr() function get the position

There are two text, text a is content and text b is list out the words line by line. The program is to get the position of words from text b in the content. This is my program: #include #include #define WORDMAXLENGTH 30 #define…
whalesf
  • 49
  • 1
  • 8
0
votes
2 answers

First occurrence return with strstr function

Following on from my previous question, it now appears that my code only outputs the first occurrence of cArray from cInput. Is there a way to get strstr to return all of the occurrences instead of stopping the program at the first? Much…
masteryupa
  • 101
  • 13
0
votes
0 answers

Limited functionality of strstr()

I need to get the substring before needle, so according to the PHP manual the function strstr should work for me, however from some reasons it does not $page = strstr($page2, $prod_close, true); The function without third argument is working fine.…
Dario
  • 1
  • 1
0
votes
2 answers

Can I search a string for character (X OR Y) in C?

I'm trying to search a string for a character to find its position in the string, however, the character can be one of three. I'm trying to achieve the equivalent of this: char *foo = strstr(string, x); where x can be either "i," "j," or "k." What…
0
votes
2 answers

c4133 warning c code

I have a problem with warning c4133, it say that the problem is incopatible types from char* to int*, I try to cast the pointer ((char*)x) but with no luck, maybe someone knows whats the problem/ this is my program, the problem in the function. void…
Tania Galan
  • 3
  • 3
  • 6
0
votes
2 answers

Coloring matching substring in strstr()

Beginner at C here. I understand that strstr() can be used for finding if strings contain a certain substring and that printf() can display colored output (as explained here: stdlib and colored output in C). What I am trying to figure out is a…
Reuben L.
  • 2,806
  • 2
  • 29
  • 45
0
votes
1 answer

How to search for a string pattern inside html, coding in C?

I need to search for titles(string) inside a html file. For this, i did the strstr to get the tag "li" which contains the tag "title= \", which contains the string that i want. For example: using this array below, i need to get the name of the book,…
renan_c
  • 3
  • 1
0
votes
1 answer

c++ string pattern matching buffer data

I have inbound buffer data from a script that I need the key => 'value' to so that I can run a math equation against it (yes, I know I need to convert to int). Since I am sure the data is string, I trying to run a pattern match against it. I see the…
brad
  • 870
  • 2
  • 13
  • 38
0
votes
2 answers

Using strstr to determine if a given string contains a string with spaces [C]

I'm working through an example of using the strstr() function. If I input "Pamela Sue Smith", why does the program output ""Pamela" is a sub-string!" and not ""Pamela Sue Smith" is a sub-string!". #include #include void…
Pandamonium
  • 111
  • 1
  • 4
0
votes
2 answers

Create an Array and get Element, or part of String, in One Line - PHP

To create an array from a string and get an element you need to do this: $string = "1/2"; $array = explode("/", $string); $elem = $array[0]; A little trick lets you use the strstr() and provides the same result as both lines above. $elem =…
0
votes
3 answers

how can i find two substrings

I can find a substring with using strstr function. For example I can find "Hello" substring, but I want to find "Hello" and "welcome". Not only one of them I want to find both of them. I want to think about "hello" and "welcome" like they are the…
0
votes
2 answers

PHP: Why do we use stristr() as a condition in an 'if' statement when its return type is string, not bool?

The question is from a statement from a piece of code from here (the last PHP program on the page) The statement is: if (stristr($q, substr($name,0,$len))) {...} But according to the manual, the return type of stristr() is string. It returns a…
Solace
  • 8,612
  • 22
  • 95
  • 183