PHP - Reading Xml Variables & Writing Variables To Xml Variable
does anyone know how to decode this XML variable value into string values? I also need to know the oposite way: creating variable values into xml. I've tried several code examples but they did filter the requested data.
Code: [Select] $xml='<?xml version="1.0" encoding="utf-8"?> <elements> <text identifier="ed9cdd4c-ae8b-4ecb-bca7-e12a5153bc02"> <value/> </text> <textarea identifier="a77f06fc-1561-453c-a429-8dd05cdc29f5"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <textarea identifier="1a85a7a6-2aba-4480-925b-6b97d311ee6c"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <image identifier="ffcc1c50-8dbd-4115-b463-b43bdcd44a57"> <file><![CDATA[images/stories/red/cars/autobedrijf.png]]></file> <title/> <link/> <target/> <rel/> <lightbox_image/> <width><![CDATA[250]]></width> <height><![CDATA[187]]></height> </image> <text identifier="4339a108-f907-4661-9aab-d6f3f00e736e"> <value><![CDATA[Kramer 5]]></value> </text> <text identifier="ea0666d7-51e3-4e52-8617-25e3ad61f8b8"> <value><![CDATA[6000 RS]]></value> </text> <text identifier="90a18889-884b-4d53-a302-4e6e4595efa0"> <value><![CDATA[Eindhoven]]></value> </text> <text identifier="410d72e0-29b3-4a92-b7d7-f01e828b1586"> <value><![CDATA[APK Pick up and return]]></value> </text> <text identifier="45b86f23-e656-4a81-bb8f-84e5ea76f71f"> <value><![CDATA[15% korting op grote beurt]]></value> </text> <text identifier="3dbbe1c6-15d6-4375-9f2f-f0e7287e29f3"> <value><![CDATA[Gratis opslag zomerbanden]]></value> </text> <text identifier="2e878db0-605d-4d58-9806-8e75bced67a4"> <value><![CDATA[Gratis abonnement of grote beurt]]></value> </text> <text identifier="94e3e08f-e008-487b-9cbd-25d108a9705e"> <value/> </text> <text identifier="73e74b73-f509-4de7-91cf-e919d14bdb0b"> <value/> </text> <text identifier="b870164b-fe78-45b0-b840-8ebceb9b9cb6"> <value><![CDATA[040 123 45 67]]></value> </text> <text identifier="8a91aab2-7862-4a04-bd28-07f1ff4acce5"> <value/> </text> <email identifier="3f15b5e4-0dea-4114-a870-1106b85248de"> <value/> <text/> <subject/> <body/> </email> <link identifier="0b3d983e-b2fa-4728-afa0-a0b640fa34dc"> <value/> <text/> <target/> <custom_title/> <rel/> </link> <relateditems identifier="7056f1d2-5253-40b6-8efd-d289b10a8c69"/> <rating identifier="cf6dd846-5774-47aa-8ca7-c1623c06e130"> <votes><![CDATA[1]]></votes> <value><![CDATA[1.0000]]></value> </rating> <googlemaps identifier="160bd40a-3e0e-48de-b6cd-56cdcc9db892"> <location><![CDATA[50.895711,5.955427]]></location> </googlemaps> </elements>'; Similar TutorialsSo here is what I have going. #1 - My weather station software processes a file and enters variables and then uploads it as a php file. #2 - Currently the station also just uploads every file to the site and enters the data in the html, but I would rather have it only upload this one file and the other pages grab data from it and print it out. I have a few php scrips in there to preform certain functions (if temp <= 32 it echos that data in blue and so on) but would rather make most of it php so I have less files being uploaded every 5 minutes. This is what the station sends to the web, but I have no idea how to get the other pages to read it and input the variables from it. So I have a text file "name.txt" in the text file I have ids and auth keys set up like this 1234564 abcdfhu 3123900 sdkoao etc How could I make it to where the ids are $ids and the auth keys are $auth_keys? I've tried using foreach() but I cant get it Hello all, I am trying to create a PHP CLi Script that will help me setup new config and server files / directories for every new web project i get instead of me having to manually create everything with each project. The script accepts the project name, and y/n for whether i want to create subdomains for css, jss and image files. After it has that, it must create a new http config file under sites-available (in Linux), by pasting the config file text. Problem : If I output regular text to the file, it displays exactly in the format that I write the string variable. But when I use a printf, or try to use variables directly in the config text, it starts formatting the text in the config file in a strange way. I just want the variables to just be replaced and the text to appear in the exact format below. The text displays perfectly as i typed below in the config file if I don't use any variables. $subDomainConfig .= '<VirtualHost *:80> ServerAdmin webmaster@%1$s ServerName %1$s.%2$s ServerAlias %1$s.%2$s # Indexes + Directory Root. DirectoryIndex index.html index.php DocumentRoot /var/www/%2$s/public_html/ # CGI Directory ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Location /cgi-bin> Options +ExecCGI </Location> # Logfiles ErrorLog /var/www/%2$s/logs/apache/error.log CustomLog /var/www/%2$s/logs/apache/access.log combined </VirtualHost> '.PHP_EOL; $httpConfigFileText = sprintf($subDomainConfig, $subDomain, $shortProjectName); The above code outputs text in this way in the file : <VirtualHost *:80> ServerAdmin webmaster@images ServerName images.mysite ServerAlias images.mysite # Indexes + Directory Root. DirectoryIndex index.html index.php DocumentRoot /var/www/mysite /public_html/ # CGI Directory ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Location /cgi-bin> Options +ExecCGI </Location> # Logfiles ErrorLog /var/www/mysite /logs/apache/error.log CustomLog /var/www/mysite /logs/apache/access.log combined </VirtualHost> It's been a while since I've dealt with text files and currently I am unable to write the contents of a variable to a text file, only the literal is being written. Should I be de-referencing or is this even possible? Also the problem is compounded by the fact that i also want to write the contents of a class display function into the text file. I have news articles which I distribute to various sites. Each article contains various hyperlinks, which must resolve to a location on the site which pulled the article, i.e. Article: (hyperlink) Widgets are wonderful. Don Doe, president of (Widgets Incorporated) say they are cool. ------ Site A: To resolve to example.com/widget-companies/Widget-news/Widgets-Incorporated. Site B: To resolve to otherexample.com/Widgets-Incorporates/widget-news I'm paralyzed. The only thing I can think of is to bring the whole article in, and do a string replace. Some of the articles are 2k+ words. Even then, I have to come up with a way of pointing out the link text. I came up with $COMPANY:WIDGETS-INCORPORATED:Widget-Incorporated (UC WIDGETS to associate it with that company, and the mixed case Widget-Incorporated would be the hyperlink text. Explode it and use it. I am not even sure it will work, or if it works whether it is too inefficient. Should I try that, or something else? Hi everyone. I am David and I am new to web design and php. I am following a Lynda.com tutorial on php and sql. I have reached a certain point in the tutorial where I am reading values back from my database in to a php variable. The variable is holding an array data type and I am accessing the element within the array. I want a HTML select control and 2 radios buttons to reflect the values in the database. Therefore the Select control should read a numeric value of type int and the radio buttons are reflecting either a 1 or a 0. Firstly the code for the Select control uses a for loop to count the array elements and load the count into the Select control. The example uses php mixed with html. The for loop will count the number of element and add a number to the select control. The an If statment is used to make a decision if the count variable equals the value in the array element $sel_subject['position'] then select that value. This does not happen, and I can not seem to get it to work. <p>Position: <select name="position"> <!--use a php block so as to use some php variables --> <!--Use these variables with the get_all_sublects function. --> <!-- This function will return all the dataset --> <?php $sel_subject = get_all_subjects(); //Then use the mysql fuction to retuen the numberic value of all the rows. $subject_count = mysql_num_rows($sel_subject); //$subject_count + 1 becauce we are adding a subject for($count=1; $count <= $subject_count+1; $count++) { echo "<option value=\"{$count}\""; if ($sel_subject['position'] == $count) { echo " selected"; } echo ">{$count}</option>"; } ?> </select> </p> Secondly the radio buttons do something similar in that i want them to reflect the value in the array element. If a 1 then True and so be checked or 0 and so false and so be unchecked. <p>Visible: <input type= "radio" name= "visible" value= "0" <?php if ($sel_subject['visible'] == 0) { echo 'checked=" checked"'; } ?> >No</input> <input type= "radio" name= "visible" value= "1" <?php if ($sel_subject['visible'] == 1) { echo 'checked=" checked"'; } ?> >Yes</input> </p> Again this doesn't work either. So in summary, I cant get the php code to affect the html form controls and relay the stored data to the user. I have been racking my brain for days and getting no where. Please can anyone help me with this. I would be very grateful. All the best Irish_Dave Hello everyone, I can get Test 2 to successfully operate the if statement using a variable variable. But when I try the same method using a session variable (Test 1) the if statement is not executed. Please could you tell me why the if statement in Test 1 is not being executed? Code: [Select] <?php # TEST 1 $_SESSION[test_variable] = "abcd"; $session_variable_name = "_SESSION[test_variable]"; if ($$session_variable_name == "abcd") { echo "<br>line 373, abcd<br>"; } # TEST 2 $test_variable = "efgh"; $test_variable_name = "test_variable"; if ($$test_variable_name == "efgh") { echo "<br>line 379, efgh<br>"; } ?> Many thanks, Stu I need to use a variable variable. I need: $row['pos_1'] $row['pos_2'] to use $i for the numbers I have this: if ($row{[pos_.$i]} == 'ad') which is throwing an error Quote Parse error: syntax error, unexpected '[' Any ideas? Thanks! I am not sure how to do the below, would variable variables be the way -- those are a new and confusing thing for me :-/ i have an array: $contactData = array('admin_firstName' => 'John', 'admin_lastName' => 'Smith', 'user_firstName' => 'Betty', user_lastName => 'Jones'); I have a function that little function that looks like this: function compare($contactSet, $var, $value){ global $contactData; $key = $contactData . "['" . $contactSet . "_" . $var ."']"; //above doesnt work, but you can see how the array key is constructed if ($key == $value) { // So, if the array key varied it would look like: // if ($contactData['admin_firstName'] == $value echo "same"; } else { echo "different"; } } and then I want to call it like this: compare('admin', 'firstName', 'John'); //would echo "same"; Any help is greatly appreciated. I have often wanted to use variable variables, or whatever this would be called, but don't know to pull it off. I can add another example if this wasnt clear enough. Question about variable variables and using session variables for them. O.K. So if I have: $foo = 3; $_SESSION['bar'] = "foo"; $$_SESSION['bar'] should equal the value of $foo, however I can't get it to work. Can someone tell me what I am doing wrong..... is it formatting??? Thanks, Thomas If I knew what to call it I could have searched it. So I will just explain. I have a form that is pulling from a database to build the following. echo <input name='$row[id]' type='text' id='$row[id]' size=2>; This will build a page that has this <input name='22' type='text' id='22' size=2> <input name='54' type='text' id='54' size=2> This part works great. The problem is when I try to add it to the database. How can I insert variables that I don't know the names of? They will be something like $_POST[22] $_POST[54] and so on. I hope someone can understand my jibberish. I am sure there is a WAY better way to do this. I know how to use $$ and ${} to use variable variables, but how would I get the same functionality out of a variable that is storing an object name? I have a function that is passed the name of an array of objects. As you can guess, that name will change based on which portion of the program is calling the function. How would I use variable variables of objects in this instance? Would it just be: Code: [Select] $this->${$objArrayName}->threadName = etc; ? To make sure I'm not being misunderstood, I have 3 arrays of objects (replies, mainThreads, and stickies) and depending on which name I pass the function, I want it to use $this->replies OR $this->mainThreads OR $this->stickies to apply properties of those objects to. Thanks for any help. -Adam I've been trying for days to get this simple 1990's code to work. It won't work. Now, I don't even want to get it to work, because it's crappy ugly 1990's code... Is there an elegant way to accomplish this? (I just want to be able to manually override the default catalog prices as needed.) <?php //default catalog prices: $sku = "123456"; $price = "5.99"; if(isset($_POST[$sku])) { // if form submitted, and if( ${$_POST[$sku]} != $price) { //...and I manually changed price $price = ${$_POST[$sku]}; //...then change price to what I input } } echo '<form name="form1" method="post" action="Crappy1990sCodePage.php">'; echo '<input type="text" name="'.$sku.'" value="'.$price.'">'; echo '<input type="text" name="'.$sku.'" value="'.$price.'">';// (same sku may be listed twice) echo '<input type="submit" class="no_class_its_the_90s_remember">' echo '</form>'; ?> Thank you 😀 Edited July 25, 2020 by StevenOliverIs it possible to split a variable into 2 variables? /// I have this sentence $item = "Below Telegraph Hill, Smallwork Canvas Edition"; /// And I want to be able to do this $item = "Below Telegraph Hill" ; $medium = "Smallwork Canvas Edition"; Is it possible to find the comma in a string, and remove the comma & everything before or after it? Any recommendations would be appreciated. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=357370.0 I'm not versed in PHP OOP and I have some code that I need to echo out onto a page. I don't know what the meaning of $ct->something is in this code. Is this an array of some type? How do I echo out the $ct->title onto another page? Use a function call? I just don't know what all of the $ct variables are and how to get to them. Any help is appreciated. Code: [Select] function current_theme_info() { $themes = get_themes(); $current_theme = get_current_theme(); if ( ! isset( $themes[$current_theme] ) ) { delete_option( 'current_theme' ); $current_theme = get_current_theme(); } $ct->name = $current_theme; $ct->title = $themes[$current_theme]['Title']; $ct->version = $themes[$current_theme]['Version']; $ct->parent_theme = $themes[$current_theme]['Parent Theme']; $ct->template_dir = $themes[$current_theme]['Template Dir']; $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; $ct->template = $themes[$current_theme]['Template']; $ct->stylesheet = $themes[$current_theme]['Stylesheet']; $ct->screenshot = $themes[$current_theme]['Screenshot']; $ct->description = $themes[$current_theme]['Description']; $ct->author = $themes[$current_theme]['Author']; $ct->tags = $themes[$current_theme]['Tags']; $ct->theme_root = $themes[$current_theme]['Theme Root']; $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI']; return $ct; } Say I have two variables like below. I basically want to select one of them, but through random choice. How do I do that? $orange = 'Orange'; $apple = 'Apple';  i have Created a Session with this code $_SESSION['USER_NAME'] = trim($_POST['username']) How can i access the $_SESSION['USER_NAME'] in other Pages ; and will this code for $var = $_SESSION[USER_NAME] can i get the SESSIOn value in " $var" variable ?? Hello, If I have this string: $tags="baseball glove face" (this can vary from 1 to 15 different words) how would i loop through and divide these into different $tag1=baseball $tag2=glove $tag3=face .. and so on (if more words) Thanks for help I am trying to achieve something that appears simple but I spent few hours in vain Quote $tag1 = '<a href="layout_m.php?k='.$k.'&name='.$name.'&type='.$type.'">'; if ($k=="1") {$history = ucfirst($name) . ' - ' . $tag1 . $k .'</a>' ; } else {$history = $history . ' - '. $tag1 . $k . '</a>' ;} print $history; This is part of a page which is involved in passing data by forms or/and URL (eg layout.php?k=1) and the display of the page depends on k. At k=1,(first page) things are ok [Joe - <a href="layout_m.php?k=1&name=Joe&type=genus"> 1 </a>] but on passing to the next page, the output is not as desired part of the variable is escaped out on the browser and breaks the variable content View source gives this: Joe - <a href= - <a href="layout_m.php?k=3&name=Joe&type=genus"> 1 </a> while I want: Joe - <a href="layout_m.php?k=1&name=Joe&type=genus"> 1 </a> - <a href="layout_m.php?k=3&name=Joe&type=genus"\> 3 </a> What I achieve to do is a simple history based on an accumulation of k EG Joe - 1 - 3 - 5 - 6 - 8 Where each number (k) is linked and when pressed each go to the corresponding keypage. |