How to use keep_in_string method of pts_strings class

Best Phoronix-test-suite code snippet using pts_strings.keep_in_string

pts_strings.php

Source:pts_strings.php Github

copy

Full Screen

...451 }452 }453 return $new_string;454 }455 public static function keep_in_string($string, $attributes)456 {457 $string_r = str_split($string);458 $new_string = null;459 foreach($string_r as $char)460 {461 if(pts_strings::char_is_of_type($char, $attributes) == true)462 {463 $new_string .= $char;464 }465 }466 return $new_string;467 }468 public static function string_only_contains($string, $attributes)469 {470 $string_r = str_split($string);471 foreach($string_r as $char)472 {473 if(pts_strings::char_is_of_type($char, $attributes) == false)474 {475 return false;476 }477 }478 return true;479 }480 public static function string_contains($string, $attributes)481 {482 $string_r = str_split($string);483 foreach($string_r as $char)484 {485 if(pts_strings::char_is_of_type($char, $attributes) == true)486 {487 return true;488 }489 }490 return false;491 }492 public static function times_occurred($string, $attributes)493 {494 $string_r = str_split($string);495 $times_matched = 0;496 foreach($string_r as $char)497 {498 if(pts_strings::char_is_of_type($char, $attributes) == true)499 {500 $times_matched++;501 }502 }503 return $times_matched;504 }505 public static function proximity_match($search, $match_to)506 {507 // Proximity search in $search string for * against $match_to508 $search = explode('*', $search);509 $is_match = true;510 if(count($search) == 1)511 {512 $is_match = false;513 }514 for($i = 0; $i < count($search) && $is_match && !empty($search[$i]); $i++)515 {516 if(($match_point = strpos($match_to, $search[$i])) !== false && ($i > 0 || $match_point == 0))517 {518 $match_to = substr($match_to, ($match_point + strlen($search[$i])));519 }520 else521 {522 $is_match = false;523 }524 }525 return $is_match;526 }527 public static function result_quantifier_to_string($quantifier)528 {529 $quantifiers = array('MAX' => 'Maximum', 'MIN' => 'Minimum', 'NULL' => null, 'AVG' => 'Average');530 return isset($quantifiers[$quantifier]) ? $quantifiers[$quantifier] : 'Average';531 }532 public static function format_time($time, $input_format = 'SECONDS', $standard_version = true, $round_to = 0)533 {534 switch($input_format)535 {536 case 'MINUTES':537 $time_in_seconds = $time * 60;538 break;539 case 'SECONDS':540 default:541 $time_in_seconds = $time;542 break;543 }544 $time_in_seconds = (int)$time_in_seconds;545 if($round_to > 0)546 {547 $time_in_seconds += $round_to - ($time_in_seconds % $round_to);548 }549 $formatted_time = array();550 if($time_in_seconds > 0)551 {552 $time_r = array();553 $time_r[0] = array(floor($time_in_seconds / 86400), 'Day');554 $time_r[1] = array(floor(($time_in_seconds % 86400) / 3600), 'Hour');555 $time_r[2] = array(floor(($time_in_seconds % 3600) / 60), 'Minute');556 $time_r[3] = array($time_in_seconds % 60, 'Second');557 foreach($time_r as $time_segment)558 {559 if($time_segment[0] > 0)560 {561 $formatted_part = $time_segment[0];562 if($standard_version)563 {564 $formatted_part .= ' ' . $time_segment[1];565 if($time_segment[0] > 1)566 {567 $formatted_part .= 's';568 }569 }570 else571 {572 $formatted_part .= strtolower(substr($time_segment[1], 0, 1));573 }574 $formatted_time[] = $formatted_part;575 }576 }577 }578 return implode(($standard_version ? ', ' : ''), $formatted_time);579 }580 public static function number_suffix_handler($n)581 {582 $suffix = 'th';583 $r = $n % 100;584 if($r < 11 || $r > 13)585 {586 switch($r % 10)587 {588 case 1:589 $suffix = 'st';590 break;591 case 2:592 $suffix = 'nd';593 break;594 case 3:595 $suffix = 'rd';596 break;597 }598 }599 return $n . $suffix;600 }601 public static function plural_handler($count, $base)602 {603 return $count . ' ' . $base . ($count != 1 ? 's' : null);604 }605 public static function days_ago_format_string($days_ago)606 {607 if($days_ago < 30)608 {609 $days_ago = pts_strings::plural_handler($days_ago, 'day');610 }611 else612 {613 $days_ago = floor($days_ago / 30);614 if($days_ago >= 12)615 {616 $year = floor($days_ago / 12);617 $months = $days_ago % 12;618 $days_ago = pts_strings::plural_handler($year, 'year');619 if($months > 0)620 {621 $days_ago .= ', ' . pts_strings::plural_handler($months, 'month');622 }623 }624 else625 {626 $days_ago = pts_strings::plural_handler($days_ago, 'month');627 }628 }629 return $days_ago;630 }631 public static function system_category_to_openbenchmark_category($category)632 {633 $categories = array('Graphics' => 'GPU', 'Processor' => 'CPU', 'System' => 'CPU', 'File-System' => 'File System');634 return isset($categories[$category]) ? $categories[$category] : $category;635 }636 public static function parse_value_string_vars($value_string)637 {638 $values = array();639 foreach(explode(';', $value_string) as $preset)640 {641 if(count($preset = pts_strings::trim_explode('=', $preset)) == 2)642 {643 $values[$preset[0]] = $preset[1];644 }645 }646 return $values;647 }648 public static function simplify_string_for_file_handling($str)649 {650 return $str == null ? '' : pts_strings::keep_in_string(trim(str_replace(array('/', '\\'), '_', $str)), pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DASH | pts_strings::CHAR_DECIMAL | pts_strings::CHAR_SPACE | pts_strings::CHAR_UNDERSCORE | pts_strings::CHAR_COMMA | pts_strings::CHAR_AT | pts_strings::CHAR_PLUS | pts_strings::CHAR_SEMICOLON | pts_strings::CHAR_EQUAL);651 }652 public static function highlight_words_with_colon($str, $pre = '<strong>', $post = '</strong>')653 {654 if($str == null)655 {656 return $str;657 }658 $str_r = explode(' ', $str);659 foreach($str_r as &$word)660 {661 if(substr($word, -1) == ':')662 {663 $word = $pre . $word . $post;664 }665 }666 return implode(' ', $str_r);667 }668 public static function highlight_diff_two_structured_strings($str1, $str2, $pre = '<span style="color: #FF0000;">', $post = '</span>')669 {670 if($str2 == null)671 {672 return $str1;673 }674 $str1 = explode(', ', $str1);675 $str2 = explode(', ', $str2);676 foreach($str1 as $i => &$word)677 {678 if(isset($str2[$i]) && $str2[$i] != $str1[$i])679 {680 $word = $pre . $word . $post;681 }682 }683 return implode(', ', $str1);684 }685 public static function is_text_string($str_check)686 {687 $is_text = false;688 if(function_exists('mb_detect_encoding'))689 {690 $is_text = mb_detect_encoding((string)$str_check, null, true) !== false;691 }692 else693 {694 // Not necessarily perfect but better than nothing...695 $is_text = strpos($str_check, "\0") === false;696 }697 /*698 // This former code tends to have false positives..699 if(function_exists('ctype_print'))700 {701 $str_check = str_replace("\t", '', $str_check);702 $str_check = str_replace("\r", '', $str_check);703 $str_check = str_replace("\n", '', $str_check);704 $is_text = ctype_print($str_check);705 }*/706 return $is_text;707 }708 public static function sanitize($input)709 {710 return htmlspecialchars($input, ENT_NOQUOTES, 'UTF-8');711 }712 public static function simple($input)713 {714 return empty($input) ? '' : pts_strings::keep_in_string($input, pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DASH | pts_strings::CHAR_DECIMAL | pts_strings::CHAR_SPACE | pts_strings::CHAR_UNDERSCORE | pts_strings::CHAR_COMMA | pts_strings::CHAR_AT | pts_strings::CHAR_COLON);715 }716}717?>...

Full Screen

Full Screen

phodevi_motherboard.php

Source:phodevi_motherboard.php Github

copy

Full Screen

...53 continue;54 }55 $vendor = pts_strings::trim_search_query(pts_strings::strip_string(pts_file_io::file_get_contents($usb_dir . 'manufacturer')));56 $device = pts_strings::trim_search_query(pts_strings::strip_string(str_replace($vendor, null, pts_file_io::file_get_contents($usb_dir . 'product'))));57 $device = pts_strings::keep_in_string($device, pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL | pts_strings::CHAR_SPACE | pts_strings::CHAR_DASH | pts_strings::CHAR_UNDERSCORE | pts_strings::CHAR_COLON | pts_strings::CHAR_COMMA);58 if($vendor == null || $device == null || $vendor == 'Generic')59 {60 continue;61 }62 array_push($usb, array(63 'Class' => pts_file_io::file_get_contents($usb_dir . 'bDeviceClass'),64 'Vendor' => $vendor,65 'Device' => $device,66 'VendorID' => pts_file_io::file_get_contents($usb_dir . 'idVendor'),67 'DeviceID' => pts_file_io::file_get_contents($usb_dir . 'idProduct')68 ));69 }70 }71 return $usb;72 }73 public static function is_genuine($mobo)74 {75 return strpos($mobo, ' ') > 1 && !pts_strings::has_in_istring($mobo, array('Virtual', 'Bochs', '440BX', 'Megatrends', 'Award ', 'Software', 'Xen', 'HVM ', 'Notebook', 'OEM ', ' KVM', 'unknown')) && !is_numeric(substr($mobo, 0, strpos($mobo, ' ')));76 // pts_strings::string_contains($mobo, pts_strings::CHAR_NUMERIC);77 }78 public static function pci_devices()79 {80 $pci_devices = array();81 if(phodevi::is_linux() && isset(phodevi::$vfs->lspci))82 {83 $lspci = phodevi::$vfs->lspci;84 $lspci = explode("\n\n", $lspci);85 foreach($lspci as $o => &$lspci_section)86 {87 $lspci_section = explode("\n", $lspci_section);88 $formatted_section = array();89 foreach($lspci_section as $i => &$line)90 {91 $line = explode(':', $line);92 if(count($line) == 2 && in_array($line[0], array('Class', 'Vendor', 'Device', 'Driver', 'Rev', 'Module')))93 {94 $line[1] = trim($line[1]);95 if(($c = strrpos($line[1], ' [')) !== false)96 {97 $id = substr($line[1], ($c + 2));98 $id = '0x' . substr($id, 0, strpos($id, ']'));99 switch($line[0])100 {101 case 'Vendor':102 $formatted_section['VendorID'] = $id;103 break;104 case 'Device':105 $formatted_section['DeviceID'] = $id;106 break;107 }108 $line[1] = substr($line[1], 0, $c);109 }110 if($line[0] == 'Class')111 {112 switch($line[1])113 {114 case 'Ethernet controller':115 case 'Network controller':116 $line[1] = 'Network';117 break;118 case 'VGA compatible controller':119 $line[1] = 'GPU';120 break;121 case 'Audio device':122 case 'Multimedia audio controller':123 $line[1] = 'Audio';124 break;125 // case 'RAM memory':126 // case 'Host bridge':127 // $line[1] = 'Chipset';128 // break;129 default:130 $line[1] = null;131 break;132 }133 }134 else if($line[0] == 'Device' || $line[0] == 'Vendor')135 {136 $line[1] = pts_strings::trim_search_query(pts_strings::strip_string($line[1]));137 $line[1] = pts_strings::keep_in_string($line[1], pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL | pts_strings::CHAR_SPACE | pts_strings::CHAR_DASH | pts_strings::CHAR_UNDERSCORE | pts_strings::CHAR_COLON | pts_strings::CHAR_COMMA);138 }139 $formatted_section[$line[0]] = $line[1];140 }141 }142 if(count($formatted_section) > 0 && $formatted_section['Class'] != null)143 {144 array_push($pci_devices, $formatted_section);145 }146 }147 }148 return $pci_devices;149 }150 public static function parse_pci_device_data(&$lspci, &$dmesg, $ignore_external_pci_devices = false)151 {...

Full Screen

Full Screen

keep_in_string

Using AI Code Generation

copy

Full Screen

1require_once 'pts_strings.php';2$test_string = 'This is a test string';3$test_string = pts_strings::keep_in_string($test_string, 'test');4echo $test_string;5require_once 'pts_strings.php';6$test_string = 'This is a test string';7$test_string = pts_strings::keep_in_string($test_string, 'test', 'string');8echo $test_string;9require_once 'pts_strings.php';10$test_string = 'This is a test string';11$test_string = pts_strings::keep_in_string($test_string, 'test', 'string', 'This');12echo $test_string;13require_once 'pts_strings.php';14$test_string = 'This is a test string';15$test_string = pts_strings::keep_in_string($test_string, 'test', 'string', 'This', 'is');16echo $test_string;17require_once 'pts_strings.php';18$test_string = 'This is a test string';19$test_string = pts_strings::keep_in_string($test_string, 'test', 'string', 'This', 'is', 'a');20echo $test_string;21require_once 'pts_strings.php';22$test_string = 'This is a test string';23$test_string = pts_strings::keep_in_string($test_string, 'test', 'string', 'This', 'is', 'a', 'This is a test string');24echo $test_string;25require_once 'pts_strings.php';26$test_string = 'This is a test string';27$test_string = pts_strings::keep_in_string($test_string, 'test', 'string', 'This', 'is

Full Screen

Full Screen

keep_in_string

Using AI Code Generation

copy

Full Screen

1require_once('pts_strings.php');2$string = 'This is a test string';3$test = pts_strings::keep_in_string($string, 'This', 'string');4echo $test;5require_once('pts_strings.php');6$string = 'This is a test string';7$test = pts_strings::keep_in_string($string, 'This', 'string', true);8echo $test;9require_once('pts_strings.php');10$string = 'This is a test string';11$test = pts_strings::keep_in_string($string, 'This', 'string', true, true);12echo $test;13require_once('pts_strings.php');14$string = 'This is a test string';15$test = pts_strings::keep_in_string($string, 'This', 'string', false, true);16echo $test;17require_once('pts_strings.php');18$string = 'This is a test string';19$test = pts_strings::keep_in_string($string, 'This', 'string', false, false);20echo $test;21require_once('pts_strings.php');22$string = 'This is a test string';23$test = pts_strings::keep_in_string($string, 'This', 'string', true, false);24echo $test;25require_once('pts_strings.php');26$string = 'This is a test string';27$test = pts_strings::keep_in_string($string, 'This', 'string', true, false, true);28echo $test;29require_once('pts_strings

Full Screen

Full Screen

keep_in_string

Using AI Code Generation

copy

Full Screen

1$mystring = 'This is a test string';2$mystring = pts_strings::keep_in_string($mystring, 'a test');3echo $mystring;4$mystring = 'This is a test string';5$mystring = pts_strings::keep_in_string($mystring, 'a test', false);6echo $mystring;

Full Screen

Full Screen

keep_in_string

Using AI Code Generation

copy

Full Screen

1include('pts_strings.php');2$pts_strings = new pts_strings();3$pts_strings->keep_in_string('My name is John Doe', 'John');4include('pts_strings.php');5$pts_strings = new pts_strings();6$pts_strings->keep_in_string('My name is John Doe', 'John');7include('pts_strings.php');8$pts_strings = new pts_strings();9$pts_strings->keep_in_string('My name is John Doe', 'John');10include('pts_strings.php');11$pts_strings = new pts_strings();12$pts_strings->keep_in_string('My name is John Doe', 'John');13include('pts_strings.php');14$pts_strings = new pts_strings();15$pts_strings->keep_in_string('My name is John Doe', 'John');

Full Screen

Full Screen

keep_in_string

Using AI Code Generation

copy

Full Screen

1include("pts_strings.php");2$pts_strings = new pts_strings();3$string = "This is a test string";4$keep = "aeiou";5$string = $pts_strings->keep_in_string($string, $keep);6echo $string;

Full Screen

Full Screen

keep_in_string

Using AI Code Generation

copy

Full Screen

1require_once('pts_strings.php');2$pts_strings = new pts_strings();3$str = 'abcdefg';4$str = $pts_strings->keep_in_string($str,'ab');5echo $str;6require_once('pts_strings.php');7$pts_strings = new pts_strings();8$str = 'abcdefg';9$str = $pts_strings->keep_in_string($str,'abc');10echo $str;11require_once('pts_strings.php');12$pts_strings = new pts_strings();13$str = 'abcdefg';14$str = $pts_strings->keep_in_string($str,'abcd');15echo $str;16require_once('pts_strings.php');17$pts_strings = new pts_strings();18$str = 'abcdefg';19$str = $pts_strings->keep_in_string($str,'abcde');20echo $str;

Full Screen

Full Screen

keep_in_string

Using AI Code Generation

copy

Full Screen

1require_once "pts_strings.php";2$mystring = "this is a string with a lot of words in it";3$mystring = pts_strings::keep_in_string($mystring, "a", "i");4echo $mystring;5require_once "pts_strings.php";6$mystring = "this is a string with a lot of words in it";7$mystring = pts_strings::keep_in_string($mystring, "a", "i", true);8echo $mystring;9require_once "pts_strings.php";10$mystring = "this is a string with a lot of words in it";11$mystring = pts_strings::keep_in_string($mystring, "a", "i", false, true);12echo $mystring;13require_once "pts_strings.php";14$mystring = "this is a string with a lot of words in it";15$mystring = pts_strings::keep_in_string($mystring, "a", "i", true, true);16echo $mystring;17require_once "pts_strings.php";18$mystring = "this is a string with a lot of words in it";

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful