Jump to content

[SOLVED] Can't seem to capture a search into arrays


Tonic-_-

Recommended Posts

Well anyways its simple.. I'm trying to addon to a IRC bot I been working on but can't get any luck with this script captuuring usernames and storing it into arrays... I'm using preg_match_all to search for : and anything after it and then store it into $matches...

 

Codex

<?php
preg_match_all("% .*?)%si", $read2[0], $matches);
$names = $matches['1'];
?>

 

 

Basically this is how the IRC prints out the name

<Tonic> bye

<UniBot> Good bye :Tonic!tonic@rox-ECDA17E4.sta.embarqhsd.net

 

I want to get the name after :

So far I get blank arrays...

 

Link to comment
Share on other sites

This should work if there is always an exclamation mark after the name.

 

<?php
$str = '<Tonic> bye
<UniBot> Good bye :Tonic!tonic@rox-ECDA17E4.sta.embarqhsd.net';

preg_match('/:(.*)!/', $str, $matches);
var_dump($matches[1]); // "Tonic"

Link to comment
Share on other sites

Well that got pretty close.. I had to implode the array back into a string but it prints out

 

:Tonic!Tonic

 

So i'm going to work with it do a few bits of trimming and see if i can get it.

 

Alright I got it.. Imploded it and separated by , then exploded back into a array and separated the strings by , :D

 

Thanks!

Link to comment
Share on other sites

There is two cells in that array.

$matches[0] = ':Tonic!' and

$matches[1] = 'Tonic'

 

Thats why you use the $matches[1] value. Not whole array together. And why you want to implode the array if you jsut want to get the name out of it?

Link to comment
Share on other sites

There is two cells in that array.

$matches[0] = ':Tonic!' and

$matches[1] = 'Tonic'

 

Thats why you use the $matches[1] value. Not whole array together. And why you want to implode the array if you jsut want to get the name out of it?

 

hh that slipped my mind, been writing the bot all day that my brain is wore out. So i'll add that to trim it down some in the coding thanks man!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.