Showing all the matches of a capture in php regex with my code [duplicate]
up vote
-1
down vote
favorite
This question already has an answer here:
PHP preg_match to find multiple occurrences
1 answer
How to echo an array in PHP?
12 answers
I have this script that gets any character that is between these two targeted characters
[ ]
so I manage to figure out how to do this in PHP but i'm facing a new problem now. I'm realizing it is only showing the first match.
i1616774134
I want to show all the matches so how can I do this and do I need to use a loop with my code? perhaps you guys will suggest a loop but I don't know how that structure will look like in my situation
so i'm clueless. I tried to use a loop with this but no success yet and I already tried preg_match_all but it gave me this error Notice: Array to string conversion when I try to use preg_match_all.
Here is my code
<?php
$string='[i1616774134][i335913688][i1986362289][i873468737][i1187566881][i297212592]';
$pattern='/[(.*?)]/';
$result = preg_match($pattern, $string, $match);
if($result){
echo $match[1].'<br/>';
}
?>
php regex
marked as duplicate by Wiktor Stribiżew
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
12 hours ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 11 more comments
up vote
-1
down vote
favorite
This question already has an answer here:
PHP preg_match to find multiple occurrences
1 answer
How to echo an array in PHP?
12 answers
I have this script that gets any character that is between these two targeted characters
[ ]
so I manage to figure out how to do this in PHP but i'm facing a new problem now. I'm realizing it is only showing the first match.
i1616774134
I want to show all the matches so how can I do this and do I need to use a loop with my code? perhaps you guys will suggest a loop but I don't know how that structure will look like in my situation
so i'm clueless. I tried to use a loop with this but no success yet and I already tried preg_match_all but it gave me this error Notice: Array to string conversion when I try to use preg_match_all.
Here is my code
<?php
$string='[i1616774134][i335913688][i1986362289][i873468737][i1187566881][i297212592]';
$pattern='/[(.*?)]/';
$result = preg_match($pattern, $string, $match);
if($result){
echo $match[1].'<br/>';
}
?>
php regex
marked as duplicate by Wiktor Stribiżew
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
12 hours ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
Usepreg_match_all
. If you want to use a more efficient pattern, use$pattern='/[([^]*)]/';
, or even$pattern='/[K[^]*/';
– Wiktor Stribiżew
12 hours ago
I already tried that it gave me an error
– Danny Lee
11 hours ago
No idea, it works well. If you want to print an array, useprint_r
, notecho
. Or, useforeach ($match[1] as $s) { echo $s ."n"; }
(see this demo).
– Wiktor Stribiżew
11 hours ago
1
See How to echo an array in PHP?
– Wiktor Stribiżew
11 hours ago
1
I posted two demo links, see 3v4l.org/OA8u9
– Wiktor Stribiżew
11 hours ago
|
show 11 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
This question already has an answer here:
PHP preg_match to find multiple occurrences
1 answer
How to echo an array in PHP?
12 answers
I have this script that gets any character that is between these two targeted characters
[ ]
so I manage to figure out how to do this in PHP but i'm facing a new problem now. I'm realizing it is only showing the first match.
i1616774134
I want to show all the matches so how can I do this and do I need to use a loop with my code? perhaps you guys will suggest a loop but I don't know how that structure will look like in my situation
so i'm clueless. I tried to use a loop with this but no success yet and I already tried preg_match_all but it gave me this error Notice: Array to string conversion when I try to use preg_match_all.
Here is my code
<?php
$string='[i1616774134][i335913688][i1986362289][i873468737][i1187566881][i297212592]';
$pattern='/[(.*?)]/';
$result = preg_match($pattern, $string, $match);
if($result){
echo $match[1].'<br/>';
}
?>
php regex
This question already has an answer here:
PHP preg_match to find multiple occurrences
1 answer
How to echo an array in PHP?
12 answers
I have this script that gets any character that is between these two targeted characters
[ ]
so I manage to figure out how to do this in PHP but i'm facing a new problem now. I'm realizing it is only showing the first match.
i1616774134
I want to show all the matches so how can I do this and do I need to use a loop with my code? perhaps you guys will suggest a loop but I don't know how that structure will look like in my situation
so i'm clueless. I tried to use a loop with this but no success yet and I already tried preg_match_all but it gave me this error Notice: Array to string conversion when I try to use preg_match_all.
Here is my code
<?php
$string='[i1616774134][i335913688][i1986362289][i873468737][i1187566881][i297212592]';
$pattern='/[(.*?)]/';
$result = preg_match($pattern, $string, $match);
if($result){
echo $match[1].'<br/>';
}
?>
This question already has an answer here:
PHP preg_match to find multiple occurrences
1 answer
How to echo an array in PHP?
12 answers
php regex
php regex
edited 11 hours ago
asked 12 hours ago
Danny Lee
1889
1889
marked as duplicate by Wiktor Stribiżew
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
12 hours ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Wiktor Stribiżew
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
12 hours ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
Usepreg_match_all
. If you want to use a more efficient pattern, use$pattern='/[([^]*)]/';
, or even$pattern='/[K[^]*/';
– Wiktor Stribiżew
12 hours ago
I already tried that it gave me an error
– Danny Lee
11 hours ago
No idea, it works well. If you want to print an array, useprint_r
, notecho
. Or, useforeach ($match[1] as $s) { echo $s ."n"; }
(see this demo).
– Wiktor Stribiżew
11 hours ago
1
See How to echo an array in PHP?
– Wiktor Stribiżew
11 hours ago
1
I posted two demo links, see 3v4l.org/OA8u9
– Wiktor Stribiżew
11 hours ago
|
show 11 more comments
2
Usepreg_match_all
. If you want to use a more efficient pattern, use$pattern='/[([^]*)]/';
, or even$pattern='/[K[^]*/';
– Wiktor Stribiżew
12 hours ago
I already tried that it gave me an error
– Danny Lee
11 hours ago
No idea, it works well. If you want to print an array, useprint_r
, notecho
. Or, useforeach ($match[1] as $s) { echo $s ."n"; }
(see this demo).
– Wiktor Stribiżew
11 hours ago
1
See How to echo an array in PHP?
– Wiktor Stribiżew
11 hours ago
1
I posted two demo links, see 3v4l.org/OA8u9
– Wiktor Stribiżew
11 hours ago
2
2
Use
preg_match_all
. If you want to use a more efficient pattern, use $pattern='/[([^]*)]/';
, or even $pattern='/[K[^]*/';
– Wiktor Stribiżew
12 hours ago
Use
preg_match_all
. If you want to use a more efficient pattern, use $pattern='/[([^]*)]/';
, or even $pattern='/[K[^]*/';
– Wiktor Stribiżew
12 hours ago
I already tried that it gave me an error
– Danny Lee
11 hours ago
I already tried that it gave me an error
– Danny Lee
11 hours ago
No idea, it works well. If you want to print an array, use
print_r
, not echo
. Or, use foreach ($match[1] as $s) { echo $s ."n"; }
(see this demo).– Wiktor Stribiżew
11 hours ago
No idea, it works well. If you want to print an array, use
print_r
, not echo
. Or, use foreach ($match[1] as $s) { echo $s ."n"; }
(see this demo).– Wiktor Stribiżew
11 hours ago
1
1
See How to echo an array in PHP?
– Wiktor Stribiżew
11 hours ago
See How to echo an array in PHP?
– Wiktor Stribiżew
11 hours ago
1
1
I posted two demo links, see 3v4l.org/OA8u9
– Wiktor Stribiżew
11 hours ago
I posted two demo links, see 3v4l.org/OA8u9
– Wiktor Stribiżew
11 hours ago
|
show 11 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
Use
preg_match_all
. If you want to use a more efficient pattern, use$pattern='/[([^]*)]/';
, or even$pattern='/[K[^]*/';
– Wiktor Stribiżew
12 hours ago
I already tried that it gave me an error
– Danny Lee
11 hours ago
No idea, it works well. If you want to print an array, use
print_r
, notecho
. Or, useforeach ($match[1] as $s) { echo $s ."n"; }
(see this demo).– Wiktor Stribiżew
11 hours ago
1
See How to echo an array in PHP?
– Wiktor Stribiżew
11 hours ago
1
I posted two demo links, see 3v4l.org/OA8u9
– Wiktor Stribiżew
11 hours ago