FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Regarding split text and match from data base
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Regarding split text and match from data base [message #183874 is a reply to message #183872] Sat, 23 November 2013 12:05 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 11/23/2013 2:52 AM, Arno Welzel wrote:
> Jerry Stuckle, 2013-11-22 19:57:
>
>> On 11/22/2013 11:50 AM, Arno Welzel wrote:
>>> Jerry Stuckle, 2013-11-22 16:54:
>>>
>>>> On 11/22/2013 10:34 AM, Arno Welzel wrote:
>>>> > Am 22.11.2013 12:28, schrieb jalaf28(at)gmail(dot)com:
>>>> >
>>>> >> Hello All I just start learning PHP and i am using 5.4.16 i just
>>>> >> want to split the out put of the following and match from the
>>>> >> database and print the System name.
>>>> >>
>>>> >> here is the Code
>>>> >>
>>>> >> <?php
>>>> >>
>>>> >> ob_start(); $line=shell_exec("arp -a"); echo "<pre>; echo $line; echo
>>>> >> "</pre>";
>>>> >>
>>>> >> ?>
>>>> >>
>>>> >> It shows the output of the command "arp -a" and show the Ip address
>>>> >> and Mac address on the LAN system. i saved the name and the Mac
>>>> >> address in the database. now i want to extaxct the command output and
>>>> >> match ["MAc address] with database and show the Particular system
>>>> >> name and Ip Address. i try google but not sufficent.
>>>> >
>>>> > You can try explode() using space (' ') as delimiter, see:
>>>> >
>>>> > <http://php.net/manual/en/function.explode.php>
>>>> >
>>>> >
>>>> >
>>>>
>>>> Arno,
>>>>
>>>> Have you actually looked at the output of arp -a? From your response, I
>>>> don't think so.
>>>
>>> And where is your answer to the question?
>>>
>>> Anyway...
>>>
>>> arp -a outputs here (numbers as "x" for privacy reasons):
>>>
>>> somename (xxx.xxx.xxx.xxx) at xx:xx:xx:xx:xx:xx [ether] on eth0
>>>
>>> So - using explode() on this line with space as delimiter should return
>>> an array with the following elements:
>>>
>>> somename
>>> (xxx.xxx.xxx.xxx)
>>> at
>>> xx:xx:xx:xx:xx:xx
>>> [ether]
>>> on
>>> eth0
>>>
>>> Then you can use the fourth element which contains the MAC address.
>>>
>>> If you get more than one line of output, the lines have to be split
>>> first of course. Therefore I'd recommend using exec() which will return
>>> the output as an array with one element for each line of output.
>>>
>>>
>>>
>>
>> My reply is above - if you bothered to read (which you obviously
>> didn't). Additionally, the output of arp -a is also dependent on the
>> operating system and version of arp. Your way requires much more
>> processing than a simple preg_match().
>
> Yep - I didn't see your other post when I wrote my reply.
>

Gee, it was only an hour before your post.

> And yes, I'm also aware that the output of arp -a depends on the
> operating system version. That's why I said - "You can try explode()"
> and not "use explode() this will always work". Of course I haven taken
> into account that the output format is not the same on all operating
> systems.
>

Then why tell him something which may not work?

>> And in this case the regex is pretty simple, and parses the output he
>> wants into a multi-dimensional array in one statement.
>
> Sury - regex is pretty simple assuming the OP knows how to use regular
> expressions ;-)
>

There is nothing complicated about his regex. A little reading of the
tutorial and one of the regex test engines should get him by very
easily. And if he still has problems, posting the output of arp -a here
and people will help him.

> But even then additional parsing may be neccessary if arp groups
> interfaces and outputs the interface description first and then a list
> of entries for that interface like Windows 7 does.
>

Not if it's done right. It would be more complicated, but a regex could
be built to process Windows output, also.

> Again - that's why I said "You can try explode()" - it was only a
> suggestion, not a complete solution. But preg_metch() is neither.
>
>

Shows how little you understand preg_match_all() (not preg_match()).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: creating key / hash
Next Topic: from mysql in associative array
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Sep 19 22:20:44 GMT 2024

Total time taken to generate the page: 0.04373 seconds