PHP - Need To Parse One Char From String And Assign It As A $var
I have a list of pictures and I want to control the order.
Here is the picture format: $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_1.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_2.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_3.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_4.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_5.jpg Notice the order 1.jpg, 2.jpg, etc.. Here is where I'm stuck... // begin stuck :) $orderPic = explode("_", $pic); foreach($orderPic as $rank){ echo "$rank"; // I need $rank to equal 1 then 2 then 3 ... } It would be nice actually if I could start the insert with number 2 because number one is always a screwy picture. I hope this makes sense / Thank for the help! Similar TutorialsHi, I have an html page with multiple image tags inside it. I'm wanting to get the full URL of a specific image within that file. The specific image I'm looking for must start with 'http://www.mysite.com/images/' in the src part of the tag to make sure I'm getting the correct image. To find the occurence, I'm using strpos() to find the character position of the string match. What I then need to do is complete the rest of the URL to get the image name and then output this. So basically I need to get the string that comes after 'http://www.mysite.com/images/' and end when the speech mark occurs to close the src part of the image tag. This will then give me the full URL of my image. How do I do this? Or is there a better way to do this? Thanks. Hello to everyone Can someone help me on how to parse this CSV string? I do not know how to parse string using PHP.. #1# "4","+447980123456","+447781484145","","2009-07-08","10:38:15","hello "","" world","Orange" "5","+447980123456","+447781484146","","2009-07-08","10:38:55","hello world","Orange" This string can contain a much bigger data. I would like the result to be Originator : +447781484145, Date : 2009-07-07, Time : 10:38:15, Message : hello world Originator : +447781484146, Date : 2009-07-08, Time : 10:38:55, Message : hello world Please guys if anyone of you knows how to parse this string it will be much appreciated. Im nearing my deadline for my work and this thing is keeping me from finishing it.. Thanks in advance I have a $string with this structure "word-word2 something-SECONDPART". I want to divide it to $string1 and $string2 by separating with the last "-". The point is that "-" exists in the first part, and I just want to make the second string after the last "-" I need parse the JSON string below into an associative array, sort it by the 'age' field and output the sorted array as an HTML table. Here is what I have done so far but it just returns me 'Array': Code: [Select] <?php $json='[{"name": "John","age": 23},{"name": "jim","age": 19},{"name": "jason","age": 34}]'; $array = json_decode( $json, true); function cmp( $a, $b){ if( !isset( $a['age']) && !isset( $b['age'])){ return 0; } if( !isset( $a['age'])){ return -1; } if( !isset( $b['age'])){ return 1; } if( $a['age'] == $b['age']){ return 0; } return (($a['age'] > $b['age']) ? 1 : -1); } usort( $array, 'cmp'); foreach ($array as $key => $value) { echo $key.":".$value."\n"; } ?> I'm trying the fetch some geocode data from mapquest. Google doesn't like me right now. I keep running into the query_limit. So I want to set a back up that will go into production when I get that error from the big G. I have my api key and I can put the string in a var. Code: [Select] $geocode = file_get_contents($url) I selected json as the output and when I echo $geocode... here is the first portion of the string....(I want lat & lng) Code: [Select] renderOptions({"results":[{"locations":[{"latLng":{"lng":-112.35984,"lat":34.58752},..... Now for the life of me, I can't do anything with it. I've tried json_decode() with the true argument there and not. Code: [Select] $output = json_decode($geocode, true); $output = json_decode($geocode); vardump($output) is NULL. So, I thought, well maybe I don't need to decode it, but I can't figure out how to parse it. I'm lost. This admittedly is my first attempt as trying to work with a jason object, but jeesh, it doesn't seem like it should be that hard. Can someone start me in the right direction? Say you have a string that you know has two, and exactly two, periods in it, like this...
$string = "3.12.8"How can you grab the three different values that are separated by periods (in this case, 3, 12 and ? I was thinking use strpos to find the position of the first period, then could use that info to grab everything up to that position. But then I couldn't figure out how you would find the position of the SECOND period. And even if I could get the exact positions of the two periods, it seems like there should be an easier way to simply retrieve values separated by specific characters. Is there a specific function for this type of thing, or was my initial though correct with having to do it in two parts essentially (find positions of periods, then use that knowledge to get the values)? Thanks! Hey all, i need a function or a way to replace each letter in a string to a star (*) Thanks Hi, I have this very simple code... <?php echo "<code>"; $hFile = fopen("myfile.ini","rt"); while(!feof($hFile)) { $string = trim(fgets($hFile,8)); $c = substr($string,0,1); if($c!="[" && $c!="\n" && $c!="\r" && $c!="") { $i = crc32($string); echo printf("%8X", $i) ."=". $string ."<br/>"; } } fclose($hFile); echo "</code>"; ?> However, it's returning results like this: Code: [Select] 4C20553D=4NATION 7BE5EF8C=4RIP EAAD529E=4SPIDER 4EB7AFA2=4WEED 7367626=4_OR_14 83101629=5CROSS When I wanted leading 0's, like this: Code: [Select] 4C20553D=4NATION 7BE5EF8C=4RIP EAAD529E=4SPIDER 4EB7AFA2=4WEED 07367626=4_OR_14 83101629=5CROSS I've tried "%.8X", which I figured would work... but it just turned all the hashes to 0. Also, which other varients of CRC are commonly used? The results I am getting are not what I expected as from another program... hello I want select first 500 char of my text and insert it as intro text and all of them for full. anyone can help me? thank you I have the following code: Code: [Select] $str = ($stringcontents[$step+38]); $str1 = ord($str); $bgcolor = convertchar($str1); ?> <td bgcolor='<?php echo $bgcolor;?>'> <span title='<?php echo $fieldname;?>' style='color: <?php echo $fgcolor;?>; font-size: 12pt'><font color="<?php echo $fgcolor;?>"><?php echo $stringcontents[$step];?></font></span> the convertchar function takes the ord value of the ASCII chr and sets a variable for bgcolor and fgcolor using HTML color codes. The background sets correctly, but the foreground ASCII chr is always black and does not use the font color code. What do I need to do to get the ASCII chr to change to a color other than black? Added: I am using a default charset: <META http-equiv="Content-Type" content="text/html; charset=IBM437"> Hi all I am trying to loop through an array and output as JSON. What I'm looking to do is create something like: Code: [Select] "something": [ {"title":"Test 1"}, {"title":"Test 2"} ], Notice that the final row has no comma. My code is as follows: <?php foreach($something as $thing): ?> <?php $something_array = array('title'=>$thingt->getId()); ?> <?php echo json_encode($something_array).','."\n"; ?> <?php endforeach; ?> I had to add a comma to the end of the array, or the JSON rows would not be ended with one. How can I get it so that, no matter how many items are in the array, the last row, wil not have the comma at the end? With the comma at the end, my JSON doesn't validate Thanks [/code] Code: Code: [Select] PostInfo,color-main,Newman,not-collapsed;Friends,color-main2,Top Friends,not-collapsed||Twitter,color-main2,Twitter,not-collapsed;Signature,color-main2,Signature,not-collapsed;AboutMe,color-transparent,About Me,not-collapsed Now I want make a function like if PostInfo = "not-collapsed" = do this/etc, So simply, how do I extract some content out of this and then use each thing to equal to if it's 'not-collapsed' or 'collapsed' ? Very hard but i think possible? ty This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347719.0 Hello I have one problem with fwrite() I have one script to get width and height from javascript and echo it with PHP. echo "Screen width is: ". $_GET['width'] ."<br />\n"; echo "Screen height is: ". $_GET['height'] ."<br />\n"; It works but i want to store the result in a file fwrite($info,"Height: $_GET['height'] <br />"); But then I get error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING //////////////////////// it would be even better if I don't have to print the values but directly store them in $iinfo sorry if something similar was soved but those examples were different or i was unable to transform it to solve my problem hi all am new to this forum help me to overcome from this error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in D:\wamp\www\quiz1\quiz1.php on line 12 Code: [Select] <?php include("contentdb.php"); $display = mysql_query("SELECT * FROM $table ORDER BY id",$db); if (!$submit) { echo "<form method=post action=$_SERVER['PHP_SELF']>"; echo "<table border=0>"; while ($row = mysql_fetch_array($display)) { $id = $row["id"]; $question = $row["question"]; $opt1 = $row["opt1"]; $opt2 = $row["opt2"]; $opt3 = $row["opt3"]; $answer = $row["answer"]; echo "<tr><td colspan=3><br><b>$question</b></td></tr>"; echo "<tr><td>$opt1 <input type=radio name=q$id value=\"$opt1\"></td><td>$opt2 <input type=radio name=q$id value=\"$opt2\"></td><td>$opt3 <input type=radio name=q$id value=\"$opt3\"></td></tr>"; } echo "</table>"; echo "<input type='submit' value='See how you did' name='submit'>"; echo "</form>"; } elseif ($submit) { $score = 0; $total = mysql_num_rows($display); while ($result = mysql_fetch_array($display)) { $answer = $result["answer"]; $q = $result["q"]; if ($$q == $answer) { $score++; } } echo "<p align=center><b>You scored $score out of $total</b></p>"; echo "<p>"; if ($score == $total) { echo "Congratulations! You got every question right!"; } elseif ($score/$total < 0.34) { echo "Oh dear. Not the best score, but don't worry, it's only a quiz."; } elseif ($score/$total > 0.67) { echo "Well done! You certainly know your stuff."; } else { echo "Not bad - but there were a few that caught you out!"; } echo "</p>"; echo "<p>Here are the answers:"; echo "<table border=0>"; $display = mysql_query("SELECT * FROM $table ORDER BY id",$db); while ($row = mysql_fetch_array($display)) { $question = $row["question"]; $answer = $row["answer"]; $q = $row["q"]; echo "<tr><td><br>$question</td></tr>"; if ($$q == $answer) { echo "<tr><td>»you answered ${$q}, which is correct</td></tr>"; } elseif ($$q == "") { echo "<tr><td>»you didn't select an answer. The answer is $answer</td></tr>"; } else { echo "<tr><td>»you answered ${$q}. The answer is $answer</td></tr>"; } } echo "</table></p>"; } ?> thanks in adavance alright, soI want to query a table and grab the last record in a desc order and assign it plus one. My code so far for testing is: <?php ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); include "connect.php"; $result = mysql_query("SELECT * FROM tickets ORDER BY id DESC LIMIT 1"); echo "<table cellpadding='4' cellspacing='4'><tr> <th>id</th></br> </tr>";while($row = mysql_fetch_array($result)) { echo "<tr><td>" . $row['id'] . "</td></tr>"; } echo "</table>"; ?> So I can display the returned value, but how can I assign the returned value to a php variable? I am trying to put a href on a line to link me to another php module, but get an error: Parse error: parse error in C:\wamp\www\editpolicy.php on line 47 My code: while ($row2 = mysql_fetch_array($result2) ) { print "<tr><td>"; <a href='editpayment.php?payid=$row2[PaymentID]'>$row2[PaymentID]</a> .........THIS IS LINE 47 ??? print "</td><td>"; print $row2['Actioned']; print "</td><td align='right'>"; print $row2['PremiumPaidAmount']; print "</td><td align='right'>"; print $row2['Risk']; print "</td></tr>"; } Hi All,
I hope someone can help!
I've got some code that passes an array of values via an ajax call. This works fine and I can see my values in the specified div:
$("#container").html(data);What I'd like to do, is get that info and pass it to a cookie. However, I'm struggling a tad. I currently have this: var set_me = html(data); $.cookie('choice',set_me, {expires: 7, path: '/'}); alert( $.cookie("choice") );But sadly it's not working. I think it's something simple but this is new to me some need some help please Thanks |