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

search and replace with pointers

Im trying to implement a 'search and replace all'. I have 2 pointers to monitor characters nclude #include #include using namespace std; const int BUFSIZE = 256; const char * const SEARCH = "the"; const char * const REPLACE = "Who is…
blitzeus
  • 485
  • 2
  • 10
  • 28
0
votes
8 answers

PHP find string within known characters

please check the following: $email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain; // prints @example.com Is there a way I can return @example without the .com? So, basically I need to search a string for a set of characters…
StudioTime
  • 22,603
  • 38
  • 120
  • 207
0
votes
1 answer

strstr the pointer used in strtok

I have a string and I use strtok to parse it. I then want to use strstr on the pointer from strtok but I keep getting a seg fault. Any thoughts on why? char *pch,*pch1,*pch2,*pch3, pch=strstr(line1,key); if(pch!=NULL){ …
JupiterOrange
  • 339
  • 2
  • 6
  • 18
0
votes
3 answers

strstr alternative for using older versions of php

I have a function that works in PHP v 5.3 and above but wondering what is the best method for doing this with a version below 5.3. My PHP version is 5.2.17 Here is my function for PHP v5.3 if (strstr($file2, '.', true) == strstr($file, '.',…
user1561466
  • 71
  • 1
  • 3
  • 11
0
votes
2 answers

PHP strstr difference issue

So currently I have a problem. I have this snippet of code to see if a phrase is present in another phrase: if(strstr($matches[1], $query)) So for example if: $matches[1] = "arctic white" $query = "arctic" In the case above, the code would detect…
S17514
  • 265
  • 2
  • 7
  • 16
-1
votes
2 answers

How to get a substring up to "\r\n\r\n"

I have the following string: HTTP/1.1 200 OK Date: Tue, 06 Dec 2011 11:53:22 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.9 Vary: Accept-Encoding Content-Encoding: gzip Content-Length: 48 Content-Type:…
Eamorr
  • 9,872
  • 34
  • 125
  • 209
-1
votes
1 answer

using in_array or strstr but the if statement does not seem to work correctly

Below is my code for the question mentioned in the title: $folder = '/net/comp/home/data/'; $files1 = scandir($folder); $analysisno=($row['ANALYSIS_NUMBER']); //e.g.11wa666 //if ($test…
donok
  • 135
  • 2
  • 11
-1
votes
2 answers

Detect array of string in another string

Im a beginner in programming and stuff, i want to solve this problem here (Spam Scanner) Spam (or junk e-mail) costs U.S. organizations billions of dollars a year in spam-prevention software, equipment, network resources, bandwidth, and lost…
MJee
  • 11
  • 3
-1
votes
1 answer

Even though memory is assigned for the variable ret, when run a segmentation fault is outputted

Output is Segmentation fault (core dumped). The line of error is line 12 but I do not understand why that would be an issue. If ret is assigned a memory location and equal to something, why is a segmentation fault outputted? Code is: #include…
-1
votes
1 answer

Why do I have a segmentation fault

#include #include int main() { //read any text file char const* const fName = "database-large.txt"; FILE* fp = fopen(fName, "r"); char *ptr; char substr[5000]; long i=0, j=0; // if file not…
-1
votes
1 answer

A better form to find a Substring in a string in assembly code (MASM)?

So i made this code with the knowledge i gather in various sites, i think there is an optimazed way to do it without pushing and poping the registers on the stack memory, but i don't know how to do it. Here is my Code comparing proc MOV CX,…
-1
votes
2 answers

Why does my program return true as the result is expected to be false?

I'm implementing the C "strstr" function in C. This function takes 2 string in parameter and tell whether or not, the 1st string contains the second one. However, while the result is expected to be false, it returns true. Could you give me an…
-1
votes
1 answer

How to find bytes in binary file C

How to find bytes in binary file. I read the binary file to a string and try to do "strstr()" It doesn't work. if I print the string in loop as %c the string is dont look the same but if I print as %x or %02hhX it looks the same. I open two binary…
-1
votes
5 answers

Function to search a text document for a word in C

I wrote this function to search a text file (which currently just says "cube") for one of the words and then call the corresponding function. However, I am getting the 'Error: No Function Found.' message. Could anyone help me in identifying my…
wohxela
  • 35
  • 6
-1
votes
1 answer

Create the strstr function in C from scratch, but with modified strings

To summarize, if the function is given arguments char *str1 = "Watch out the streets?"; char *str2 = "street?";, it should return a pointer in str1 to the first instance of "street", starting from s. I am completely stuck and appreciate any help. I…
John
  • 35
  • 4