Jump to content

Regular expression


sandy1028

Recommended Posts

When using preg_match_all, it will always be stored into a multidimensional array. So long as you know which part of the array to access, it shouldn't be problematic.. so in this case, if you know you have use what is in $matches[1], then simply utilize that part of the array (ignoring the rest).

 

You could simply use a foreach loop on $matches[1] and store this into a new one dimensional array:

 

preg_match_all("#<ite>(.*?)(?=</ite>)#",$string,$matches);
$matchedInfo = array(); // this will be your new one dimensional array
foreach($matches[1] as $key => $val){
$matchedInfo[$key] = $val;
echo $matchedInfo[$key] . "<br />\n";
}

Link to comment
https://forums.phpfreaks.com/topic/156072-regular-expression/#findComment-821973
Share on other sites

www.aaa.com/ - 3k

 

How to extract only www.aaa.com using regular expressions.

 

If your output is www.aaa.com/ and you just want www.aaa.com simply use substr...

 

$url = substr($url, 0, (strlen($url) - 1));

 

Should chop off the last character for you.

 

 

Link to comment
https://forums.phpfreaks.com/topic/156072-regular-expression/#findComment-823473
Share on other sites

You could simply use a foreach loop on $matches[1] and store this into a new one dimensional array:

 

preg_match_all("#<ite>(.*?)(?=</ite>)#",$string,$matches);
$matchedInfo = array(); // this will be your new one dimensional array
foreach($matches[1] as $key => $val){
$matchedInfo[$key] = $val;
echo $matchedInfo[$key] . "<br />\n";
}

 

Or you could just do $matchedInfo = $matches[1]. That would be easier :P

Link to comment
https://forums.phpfreaks.com/topic/156072-regular-expression/#findComment-824915
Share on other sites

You could simply use a foreach loop on $matches[1] and store this into a new one dimensional array:

 

preg_match_all("#<ite>(.*?)(?=</ite>)#",$string,$matches);
$matchedInfo = array(); // this will be your new one dimensional array
foreach($matches[1] as $key => $val){
$matchedInfo[$key] = $val;
echo $matchedInfo[$key] . "<br />\n";
}

 

Or you could just do $matchedInfo = $matches[1]. That would be easier :P

 

Indeed, hence:

So long as you know which part of the array to access, it shouldn't be problematic.. so in this case, if you know you have use what is in $matches[1], then simply utilize that part of the array (ignoring the rest).

 

I figured the $matches[1] was self explanatory (perhaps not?)... I suggested the alternative in case the OP still wasn't comfortable with dealing with even part of a multi-dimensional array (it wouldn't be the path I would take, as I understand how to access $matches[1].. but yeah, perhaps I should have actually given the $matchedInfo = $matches[1] sample as you have done, and if that was still not comfortable enough for the OP, then move to plan b. My bad.

 

P.S didn't even know about the [tt] tag... Heh... learn something new every day. (tt= tinytext?)

Link to comment
https://forums.phpfreaks.com/topic/156072-regular-expression/#findComment-824931
Share on other sites

Hehe.. yeah, you don't want that purple monster coming at you.. he may look harmless, but given his raw mass (and lack of ability to feel pain because he's always god damn happy), he'll mess you up.

 

 

I'm looking over at the Simple Machines website on bbc tags (as I really am curious which ones actually exist). If I'm not mistaken, [m]..[/m] is a phpfreaks custom built one (correct?), but is there any additional ones not from SM?

 


 

P.S Yeah, just saw the tt in the list:

[tt]text[/tt] Formats enclosed text in teletype format.

 

I figured it was a custom tag, but could have simply looked it up  :-\

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/156072-regular-expression/#findComment-825083
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.