I have a text string that looks like
var1=red&var2=green&var3=blue&var4=magenta
How to manipulate this string to isolate the value var2, which in this case is equalgreen
var2
green
I would start with parse_url What looks pretty close to the URL parameter line, which you could use the built-in methods for processing URLs.
Use the php parse_str () function to convert it to an array.
parse_str($str, $vars); echo $vars['var2'];
:
parse_str($str,$tmp); // $tmp['var2'] is now what you're looking for
parse_str /. , .
parse_str
<?php $str = 'var1=red&var2=green&var3=blue&var4=magenta'; parse_str($str, $output); $result = null; foreach($output as $k => $v){ if($v == 'green'){ $result = $k; break; } } ?>
Source: https://habr.com/ru/post/1777577/More articles:Best way to handle screen orientation Change when working with dynamically generated views? - androidGPL library for testing integration, but does not require distribution - licensingPython: the 'list' object does not have the 'read' attribute - pythonЧтение файла JDF - c#Delphi code to enable screen saver does not work in Windows 7 - windows-7Can Google Maps display custom KML icons at any zoom level? - google-mapsEnlarged stack does not work - c ++the default assignment operator is c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1777581/example-of-code-which-incorrectly-tries-to-re-seat-a-reference&usg=ALkJrhgFYPJ6dmM6KfU--1-qUYmWbf6GeAHow to get BoundField value in django template? - djangoAll Articles