Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:33:00+00:00 2026-06-12T07:33:00+00:00

From the topic itself, I need to compare a string to a line of

  • 0

From the topic itself, I need to compare a string to a line of text inside a textarea.

Here’s the output i got from php from my linux server which i have program that prints for devices that are available and i put it inside a textarea.

Device --------------      |        NAme       ------------------- |        Status  

/dev/ttyS0-----------| Profilic |-------------------|Available

/dev/ttyUSB0 -------| Test | ---------------------|Busy

Now I have an array of devices..

$devices = array("/dev/ttyS0", "/dev/ttyUSB0", "/dev/ttyUSB1");

Now how can i compare my array of strings if the following devices in the textarea exist?

Say if /dev/ttyS0 found in the textarea then it returns true because i have /dev/ttyS0 in my array of strings.

Sample code how i get output from linux to php.

echo "<textarea>";   
echo stream_get_contents($pipes[1]); 
echo "</textarea>";

What i Want to happen.(mockup code)

if(/dev/ttyS0 == in the textarea){
  enable this part of code
}

if(/dev/ttyUSB0 == in the textarea){
  enable this part of code
}

and so on....

How can i do that?..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:33:01+00:00Added an answer on June 12, 2026 at 7:33 am

    Assuming your device descriptors should appear at the start of a line in the textarea by your format above, you can iterate over the lines and look for strpos($line, $device) === 0.

    $lines = explode("\n", $teextarea_content);
    // loop over array of device descriptors
    // and make an array of those found in the textarea
    $found_devices = array();
    foreach ($devices as $device) {
      // Iterate over lines in the textarea
      foreach ($lines as $line) {
        if (strpos($line, $device) === 0) {
          // And add the device to your array if found, then break
          // out of the inner loop
          $found_devices[] = $device;
          break;
        }
      } 
    }
    // These are the devices you found...
    var_dump($found_devices);
    
    // Finally, enable your blocks.
    if (in_array("/dev/ttyUSB0", $found_devices)) {
       // enable for /dev/ttyUSB0
    }
    // do the same for your other devices as necessary
    
    // OR... You could use a fancy switch in a loop to act on each of the found devices
    // Useful if two or more of them require the same action.
    foreach ($found_devices as $fd) {
      switch($fd) {
        case '/dev/ttyUSB0':
          // stuff for this device
          break;
        case '/dev/ttyS0':
          // stuff for this device
          break;
        // These two need the same action so use a fallthrough
        case '/dev/ttyS1':
        case '/dev/ttyS2':
          // Stuff for these two...
          break;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

topic.php $id = isset($_GET['id']) ? intval($_GET['id']) : 0; $query = mysql_query(SELECT * FROM topics
I have some C# code I got from http://bytes.com/topic/c-sharp/answers/572657-net-clipboard-metafiles that copies a cell range
From the topic itself, how am i supposed to do that?... I'm getting the
I found out how to retreive the html page of a topic from google
In our application, we receive messages from JMS Topic. First I want to know
From the Mojolicious wiki on the topic of Database support: Although SQL::Abstract looks like
as the topic says, my upper div starts from the margin of the lower
I have downloaded some files from the internet related to a particular topic. Now
I need a way to remove unused images from my filesystem, i.e. images that
Sorry for opening this topic again, but thinking about this topic itself has started

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.