How to search for string in array?
I have a string in a custom field usp-custom-60
:
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Then I get a value from GET
$myTerm = $_GET['cityName'];
And now $myterm
is genova
And I have a loop where I am first trying to split the whole string and convert it into an array, then I am asking if a term is in array:
$catIds = array();
while {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
$custom_field = explode(" ", $custom_field);
if (in_array($myTerm, $custom_field, true)) {
array_push($catIds, $id);
var_dump($catIds);
}
But I get no results. If I do var_dump($custom_field)
I get;
array(8) { [0]=> string(3) "Via" [1]=> string(8) "Prospero" [2]=> string(10) "Lavarello," [3]=> string(2) "2," [4]=> string(5) "16142" [5]=> string(6) "Genova" [6]=> string(3) "GE," [7]=> string(6) "Italia" } array(8) { [0]=> string(3) "Via" [1]=> string(8) "Prospero" [2]=> string(10) "Lavarello," [3]=> string(2) "2," [4]=> string(5) "16142" [5]=> string(6) "Genova" [6]=> string(3) "GE," [7]=> string(6) "Italia" } array(8) { [0]=> string(3) "Via" [1]=> string(9) "Adalberto" [2]=> string(7) "Catena," [3]=> string(2) "4," [4]=> string(5) "20121" [5]=> string(6) "Milano" [6]=> string(3) "MI," [7]=> string(6) "Italia" }
Based on the other answer suggested, I tried the following
$myTerm = $_GET['cityName'];
$catIds = array();
$args = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => -1,
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
if (strpos($custom_field, $myTerm) !== false) {
array_push($catIds, $id);
}
if(count($catIds) > 0){
$arrayFUllCity = "fullCity";
} else {
$arrayFUllCity = "empty";
}
}
//$catIds = implode( ", ", $catIds );
var_dump($catIds);
}
But I get array(0) { }
even tho the echo $custom_field
gives me 3 results with
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Via Adalberto Catena, 4, 20121 Milano MI, Italia
php
|
show 1 more comment
I have a string in a custom field usp-custom-60
:
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Then I get a value from GET
$myTerm = $_GET['cityName'];
And now $myterm
is genova
And I have a loop where I am first trying to split the whole string and convert it into an array, then I am asking if a term is in array:
$catIds = array();
while {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
$custom_field = explode(" ", $custom_field);
if (in_array($myTerm, $custom_field, true)) {
array_push($catIds, $id);
var_dump($catIds);
}
But I get no results. If I do var_dump($custom_field)
I get;
array(8) { [0]=> string(3) "Via" [1]=> string(8) "Prospero" [2]=> string(10) "Lavarello," [3]=> string(2) "2," [4]=> string(5) "16142" [5]=> string(6) "Genova" [6]=> string(3) "GE," [7]=> string(6) "Italia" } array(8) { [0]=> string(3) "Via" [1]=> string(8) "Prospero" [2]=> string(10) "Lavarello," [3]=> string(2) "2," [4]=> string(5) "16142" [5]=> string(6) "Genova" [6]=> string(3) "GE," [7]=> string(6) "Italia" } array(8) { [0]=> string(3) "Via" [1]=> string(9) "Adalberto" [2]=> string(7) "Catena," [3]=> string(2) "4," [4]=> string(5) "20121" [5]=> string(6) "Milano" [6]=> string(3) "MI," [7]=> string(6) "Italia" }
Based on the other answer suggested, I tried the following
$myTerm = $_GET['cityName'];
$catIds = array();
$args = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => -1,
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
if (strpos($custom_field, $myTerm) !== false) {
array_push($catIds, $id);
}
if(count($catIds) > 0){
$arrayFUllCity = "fullCity";
} else {
$arrayFUllCity = "empty";
}
}
//$catIds = implode( ", ", $catIds );
var_dump($catIds);
}
But I get array(0) { }
even tho the echo $custom_field
gives me 3 results with
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Via Adalberto Catena, 4, 20121 Milano MI, Italia
php
I don't entirely follow--can you not usestrpos
? php.net/manual/en/function.strpos.php
– ggorlen
Nov 21 '18 at 0:43
@ggorlen why strops? I have an entire string, I need to check if $myterm is in string
– rob.m
Nov 21 '18 at 0:44
@rob.m That's exactly whatstrpos
does, check if a string is in a string.
– ggorlen
Nov 21 '18 at 0:45
Possible duplicate of How do I check if a string contains a specific word?
– ggorlen
Nov 21 '18 at 0:47
@ggorlen question updated
– rob.m
Nov 21 '18 at 0:52
|
show 1 more comment
I have a string in a custom field usp-custom-60
:
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Then I get a value from GET
$myTerm = $_GET['cityName'];
And now $myterm
is genova
And I have a loop where I am first trying to split the whole string and convert it into an array, then I am asking if a term is in array:
$catIds = array();
while {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
$custom_field = explode(" ", $custom_field);
if (in_array($myTerm, $custom_field, true)) {
array_push($catIds, $id);
var_dump($catIds);
}
But I get no results. If I do var_dump($custom_field)
I get;
array(8) { [0]=> string(3) "Via" [1]=> string(8) "Prospero" [2]=> string(10) "Lavarello," [3]=> string(2) "2," [4]=> string(5) "16142" [5]=> string(6) "Genova" [6]=> string(3) "GE," [7]=> string(6) "Italia" } array(8) { [0]=> string(3) "Via" [1]=> string(8) "Prospero" [2]=> string(10) "Lavarello," [3]=> string(2) "2," [4]=> string(5) "16142" [5]=> string(6) "Genova" [6]=> string(3) "GE," [7]=> string(6) "Italia" } array(8) { [0]=> string(3) "Via" [1]=> string(9) "Adalberto" [2]=> string(7) "Catena," [3]=> string(2) "4," [4]=> string(5) "20121" [5]=> string(6) "Milano" [6]=> string(3) "MI," [7]=> string(6) "Italia" }
Based on the other answer suggested, I tried the following
$myTerm = $_GET['cityName'];
$catIds = array();
$args = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => -1,
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
if (strpos($custom_field, $myTerm) !== false) {
array_push($catIds, $id);
}
if(count($catIds) > 0){
$arrayFUllCity = "fullCity";
} else {
$arrayFUllCity = "empty";
}
}
//$catIds = implode( ", ", $catIds );
var_dump($catIds);
}
But I get array(0) { }
even tho the echo $custom_field
gives me 3 results with
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Via Adalberto Catena, 4, 20121 Milano MI, Italia
php
I have a string in a custom field usp-custom-60
:
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Then I get a value from GET
$myTerm = $_GET['cityName'];
And now $myterm
is genova
And I have a loop where I am first trying to split the whole string and convert it into an array, then I am asking if a term is in array:
$catIds = array();
while {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
$custom_field = explode(" ", $custom_field);
if (in_array($myTerm, $custom_field, true)) {
array_push($catIds, $id);
var_dump($catIds);
}
But I get no results. If I do var_dump($custom_field)
I get;
array(8) { [0]=> string(3) "Via" [1]=> string(8) "Prospero" [2]=> string(10) "Lavarello," [3]=> string(2) "2," [4]=> string(5) "16142" [5]=> string(6) "Genova" [6]=> string(3) "GE," [7]=> string(6) "Italia" } array(8) { [0]=> string(3) "Via" [1]=> string(8) "Prospero" [2]=> string(10) "Lavarello," [3]=> string(2) "2," [4]=> string(5) "16142" [5]=> string(6) "Genova" [6]=> string(3) "GE," [7]=> string(6) "Italia" } array(8) { [0]=> string(3) "Via" [1]=> string(9) "Adalberto" [2]=> string(7) "Catena," [3]=> string(2) "4," [4]=> string(5) "20121" [5]=> string(6) "Milano" [6]=> string(3) "MI," [7]=> string(6) "Italia" }
Based on the other answer suggested, I tried the following
$myTerm = $_GET['cityName'];
$catIds = array();
$args = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => -1,
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
if (strpos($custom_field, $myTerm) !== false) {
array_push($catIds, $id);
}
if(count($catIds) > 0){
$arrayFUllCity = "fullCity";
} else {
$arrayFUllCity = "empty";
}
}
//$catIds = implode( ", ", $catIds );
var_dump($catIds);
}
But I get array(0) { }
even tho the echo $custom_field
gives me 3 results with
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Via Prospero Lavarello, 2, 16142 Genova GE, Italia
Via Adalberto Catena, 4, 20121 Milano MI, Italia
php
php
edited Nov 21 '18 at 0:52
rob.m
asked Nov 21 '18 at 0:41
rob.mrob.m
3,830113985
3,830113985
I don't entirely follow--can you not usestrpos
? php.net/manual/en/function.strpos.php
– ggorlen
Nov 21 '18 at 0:43
@ggorlen why strops? I have an entire string, I need to check if $myterm is in string
– rob.m
Nov 21 '18 at 0:44
@rob.m That's exactly whatstrpos
does, check if a string is in a string.
– ggorlen
Nov 21 '18 at 0:45
Possible duplicate of How do I check if a string contains a specific word?
– ggorlen
Nov 21 '18 at 0:47
@ggorlen question updated
– rob.m
Nov 21 '18 at 0:52
|
show 1 more comment
I don't entirely follow--can you not usestrpos
? php.net/manual/en/function.strpos.php
– ggorlen
Nov 21 '18 at 0:43
@ggorlen why strops? I have an entire string, I need to check if $myterm is in string
– rob.m
Nov 21 '18 at 0:44
@rob.m That's exactly whatstrpos
does, check if a string is in a string.
– ggorlen
Nov 21 '18 at 0:45
Possible duplicate of How do I check if a string contains a specific word?
– ggorlen
Nov 21 '18 at 0:47
@ggorlen question updated
– rob.m
Nov 21 '18 at 0:52
I don't entirely follow--can you not use
strpos
? php.net/manual/en/function.strpos.php– ggorlen
Nov 21 '18 at 0:43
I don't entirely follow--can you not use
strpos
? php.net/manual/en/function.strpos.php– ggorlen
Nov 21 '18 at 0:43
@ggorlen why strops? I have an entire string, I need to check if $myterm is in string
– rob.m
Nov 21 '18 at 0:44
@ggorlen why strops? I have an entire string, I need to check if $myterm is in string
– rob.m
Nov 21 '18 at 0:44
@rob.m That's exactly what
strpos
does, check if a string is in a string.– ggorlen
Nov 21 '18 at 0:45
@rob.m That's exactly what
strpos
does, check if a string is in a string.– ggorlen
Nov 21 '18 at 0:45
Possible duplicate of How do I check if a string contains a specific word?
– ggorlen
Nov 21 '18 at 0:47
Possible duplicate of How do I check if a string contains a specific word?
– ggorlen
Nov 21 '18 at 0:47
@ggorlen question updated
– rob.m
Nov 21 '18 at 0:52
@ggorlen question updated
– rob.m
Nov 21 '18 at 0:52
|
show 1 more comment
2 Answers
2
active
oldest
votes
Your issue (as far as I can see is that you have a case mismatch between $myTerm
which is "genova"
and the string, which has "Genova"
in it. Since in_array
is case-sensitive, the check fails. I would use preg_match
on the original string to solve this, using b
to check for word boundaries around $myTerm
, and the i
modifier to make the regex case-insensitive:
$custom_fields = 'Via Prospero Lavarello, 2, 16142 Genova GE, Italia';
$myTerm = 'genova';
echo preg_match("/b$myTermb/i", $custom_fields);
Output:
1 (true)
Demo on 3v4l.org
add a comment |
In this kind of case using strpos
is best way.
From my end it's not possible to run your code because of database relationship. but you can try this solution. May be problem in extra spacing.
$catIds = array();
while {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
$custom_field = explode(" ", $custom_field);
$custom_field = array_map('trim', $custom_field);
if (in_array($myTerm, $custom_field, true)) {
array_push($catIds, $id);
var_dump($catIds);
}
I still getarray(0) { }
even tho the strings are as per the bottom of my question
– rob.m
Nov 21 '18 at 0:54
try to echo $id to be sure $id is not blank.
– Himel Rana
Nov 21 '18 at 1:00
if I place echo $id before in_array, I get 127431 127429 127427 array(0) { }
– rob.m
Nov 21 '18 at 1:03
this isn't working $custom_field = explode(" ", $custom_field);
– rob.m
Nov 21 '18 at 1:04
explode should work. check your $custom_field >> echo $coustom_field; before explode
– Himel Rana
Nov 21 '18 at 1:13
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403728%2fhow-to-search-for-string-in-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your issue (as far as I can see is that you have a case mismatch between $myTerm
which is "genova"
and the string, which has "Genova"
in it. Since in_array
is case-sensitive, the check fails. I would use preg_match
on the original string to solve this, using b
to check for word boundaries around $myTerm
, and the i
modifier to make the regex case-insensitive:
$custom_fields = 'Via Prospero Lavarello, 2, 16142 Genova GE, Italia';
$myTerm = 'genova';
echo preg_match("/b$myTermb/i", $custom_fields);
Output:
1 (true)
Demo on 3v4l.org
add a comment |
Your issue (as far as I can see is that you have a case mismatch between $myTerm
which is "genova"
and the string, which has "Genova"
in it. Since in_array
is case-sensitive, the check fails. I would use preg_match
on the original string to solve this, using b
to check for word boundaries around $myTerm
, and the i
modifier to make the regex case-insensitive:
$custom_fields = 'Via Prospero Lavarello, 2, 16142 Genova GE, Italia';
$myTerm = 'genova';
echo preg_match("/b$myTermb/i", $custom_fields);
Output:
1 (true)
Demo on 3v4l.org
add a comment |
Your issue (as far as I can see is that you have a case mismatch between $myTerm
which is "genova"
and the string, which has "Genova"
in it. Since in_array
is case-sensitive, the check fails. I would use preg_match
on the original string to solve this, using b
to check for word boundaries around $myTerm
, and the i
modifier to make the regex case-insensitive:
$custom_fields = 'Via Prospero Lavarello, 2, 16142 Genova GE, Italia';
$myTerm = 'genova';
echo preg_match("/b$myTermb/i", $custom_fields);
Output:
1 (true)
Demo on 3v4l.org
Your issue (as far as I can see is that you have a case mismatch between $myTerm
which is "genova"
and the string, which has "Genova"
in it. Since in_array
is case-sensitive, the check fails. I would use preg_match
on the original string to solve this, using b
to check for word boundaries around $myTerm
, and the i
modifier to make the regex case-insensitive:
$custom_fields = 'Via Prospero Lavarello, 2, 16142 Genova GE, Italia';
$myTerm = 'genova';
echo preg_match("/b$myTermb/i", $custom_fields);
Output:
1 (true)
Demo on 3v4l.org
edited Nov 21 '18 at 3:30
answered Nov 21 '18 at 1:55
NickNick
35.1k132143
35.1k132143
add a comment |
add a comment |
In this kind of case using strpos
is best way.
From my end it's not possible to run your code because of database relationship. but you can try this solution. May be problem in extra spacing.
$catIds = array();
while {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
$custom_field = explode(" ", $custom_field);
$custom_field = array_map('trim', $custom_field);
if (in_array($myTerm, $custom_field, true)) {
array_push($catIds, $id);
var_dump($catIds);
}
I still getarray(0) { }
even tho the strings are as per the bottom of my question
– rob.m
Nov 21 '18 at 0:54
try to echo $id to be sure $id is not blank.
– Himel Rana
Nov 21 '18 at 1:00
if I place echo $id before in_array, I get 127431 127429 127427 array(0) { }
– rob.m
Nov 21 '18 at 1:03
this isn't working $custom_field = explode(" ", $custom_field);
– rob.m
Nov 21 '18 at 1:04
explode should work. check your $custom_field >> echo $coustom_field; before explode
– Himel Rana
Nov 21 '18 at 1:13
|
show 3 more comments
In this kind of case using strpos
is best way.
From my end it's not possible to run your code because of database relationship. but you can try this solution. May be problem in extra spacing.
$catIds = array();
while {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
$custom_field = explode(" ", $custom_field);
$custom_field = array_map('trim', $custom_field);
if (in_array($myTerm, $custom_field, true)) {
array_push($catIds, $id);
var_dump($catIds);
}
I still getarray(0) { }
even tho the strings are as per the bottom of my question
– rob.m
Nov 21 '18 at 0:54
try to echo $id to be sure $id is not blank.
– Himel Rana
Nov 21 '18 at 1:00
if I place echo $id before in_array, I get 127431 127429 127427 array(0) { }
– rob.m
Nov 21 '18 at 1:03
this isn't working $custom_field = explode(" ", $custom_field);
– rob.m
Nov 21 '18 at 1:04
explode should work. check your $custom_field >> echo $coustom_field; before explode
– Himel Rana
Nov 21 '18 at 1:13
|
show 3 more comments
In this kind of case using strpos
is best way.
From my end it's not possible to run your code because of database relationship. but you can try this solution. May be problem in extra spacing.
$catIds = array();
while {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
$custom_field = explode(" ", $custom_field);
$custom_field = array_map('trim', $custom_field);
if (in_array($myTerm, $custom_field, true)) {
array_push($catIds, $id);
var_dump($catIds);
}
In this kind of case using strpos
is best way.
From my end it's not possible to run your code because of database relationship. but you can try this solution. May be problem in extra spacing.
$catIds = array();
while {
$query->the_post();
$id = get_the_ID();
$custom_field = usp_get_meta(false, 'usp-custom-60');
$custom_field = explode(" ", $custom_field);
$custom_field = array_map('trim', $custom_field);
if (in_array($myTerm, $custom_field, true)) {
array_push($catIds, $id);
var_dump($catIds);
}
edited Nov 21 '18 at 0:56
Funk Forty Niner
1
1
answered Nov 21 '18 at 0:53
Himel RanaHimel Rana
43129
43129
I still getarray(0) { }
even tho the strings are as per the bottom of my question
– rob.m
Nov 21 '18 at 0:54
try to echo $id to be sure $id is not blank.
– Himel Rana
Nov 21 '18 at 1:00
if I place echo $id before in_array, I get 127431 127429 127427 array(0) { }
– rob.m
Nov 21 '18 at 1:03
this isn't working $custom_field = explode(" ", $custom_field);
– rob.m
Nov 21 '18 at 1:04
explode should work. check your $custom_field >> echo $coustom_field; before explode
– Himel Rana
Nov 21 '18 at 1:13
|
show 3 more comments
I still getarray(0) { }
even tho the strings are as per the bottom of my question
– rob.m
Nov 21 '18 at 0:54
try to echo $id to be sure $id is not blank.
– Himel Rana
Nov 21 '18 at 1:00
if I place echo $id before in_array, I get 127431 127429 127427 array(0) { }
– rob.m
Nov 21 '18 at 1:03
this isn't working $custom_field = explode(" ", $custom_field);
– rob.m
Nov 21 '18 at 1:04
explode should work. check your $custom_field >> echo $coustom_field; before explode
– Himel Rana
Nov 21 '18 at 1:13
I still get
array(0) { }
even tho the strings are as per the bottom of my question– rob.m
Nov 21 '18 at 0:54
I still get
array(0) { }
even tho the strings are as per the bottom of my question– rob.m
Nov 21 '18 at 0:54
try to echo $id to be sure $id is not blank.
– Himel Rana
Nov 21 '18 at 1:00
try to echo $id to be sure $id is not blank.
– Himel Rana
Nov 21 '18 at 1:00
if I place echo $id before in_array, I get 127431 127429 127427 array(0) { }
– rob.m
Nov 21 '18 at 1:03
if I place echo $id before in_array, I get 127431 127429 127427 array(0) { }
– rob.m
Nov 21 '18 at 1:03
this isn't working $custom_field = explode(" ", $custom_field);
– rob.m
Nov 21 '18 at 1:04
this isn't working $custom_field = explode(" ", $custom_field);
– rob.m
Nov 21 '18 at 1:04
explode should work. check your $custom_field >> echo $coustom_field; before explode
– Himel Rana
Nov 21 '18 at 1:13
explode should work. check your $custom_field >> echo $coustom_field; before explode
– Himel Rana
Nov 21 '18 at 1:13
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403728%2fhow-to-search-for-string-in-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I don't entirely follow--can you not use
strpos
? php.net/manual/en/function.strpos.php– ggorlen
Nov 21 '18 at 0:43
@ggorlen why strops? I have an entire string, I need to check if $myterm is in string
– rob.m
Nov 21 '18 at 0:44
@rob.m That's exactly what
strpos
does, check if a string is in a string.– ggorlen
Nov 21 '18 at 0:45
Possible duplicate of How do I check if a string contains a specific word?
– ggorlen
Nov 21 '18 at 0:47
@ggorlen question updated
– rob.m
Nov 21 '18 at 0:52