PHP - Priting 8 Char Hex
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... 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. Hey all, i need a function or a way to replace each letter in a string to a star (*) Thanks 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 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] 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"> 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! 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 I have a text file that contain something like this : question.txt ------------------------ 12/10/2010 Quest : Was a web designer really care about your web security other than thinking so hard to design your web just based on how the web will looks like?. >>from:sombody@somwhere.com,opinion=not at all,comment:your site are cool 11/10/2010 Quest : Was a web designer really love his girl friend in other side they r almost got no time dating with her? >>from:sombody@somwhere.net,opinion=he loves computer,comment:your site are waste. ------------------------- All i need to do is, grabing all informations after the char ">>" and write it to another text file name "output.txt" that will contain : output.txt --------------------- from:sombody@somwhere.com,opinion=not at all,comment:your site are cool from:sombody@somwhere.net,opinion=he loves computer,comment:your site are waste. --------------------- can some one show me the way? thanks. |