I have one field in a database table with the following rows
show_email_icon= show_hits= feed_summary= page_title= show_page_title=1 pageclass_sfx= menu_image=hd_events.png secure=0
All content is stored as text in a single mysql table field. Now I want to get menu_image. How can i get this?
If you use PHP5.3 or higher, you can use parse_ini_string()one that will give you a nice associative array:
parse_ini_string()
$str = fetch_from_db(); $array = parse_ini_string($str); echo $array['menu_image']; // hd_events.png
Try
if (preg_match('/^menu_image\\s*=\\s*(.*)$/m', $t, $matches)) { //the content is $matches[1]; }
You should consider having a table with two columns "key" and "value", and then
SELECT value from table_name WHERE key = 'menu_image';
, Artefacto. - , un-joomla-ify :
preg_match_all("/(.*)=(.*)/", $dbString, $matches); $settings = array(); for($i = 0; $i < count($matches[1]); $i++) $settings[$matches[1][$i]] = $matches[2][$i]; // Use $settings['menu_image'] or any of the others
Source: https://habr.com/ru/post/1748783/More articles:Determine if javascript is complete - javascriptParse text from the capture screen - javaThe maximum number of C ++ compiler classes is c ++Отсутствует ошибка Java при условном выражении? - javaПодключение к службе SFTP через Java Runtime - javaUnable to pass one parameter to lambda function in MVVM Light Toolkit RelayCommand - wpfPrivate Java source applications - javaUsing excel import wizard through code? - c #Image maps for Openstreetmaps (OSM) and Google Maps (satellite view) - google-mapsiPhone: не может анимировать контент. В процессе анимации Nav Bar отображается/скрывается. - iphoneAll Articles