Jump to content

x2i

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://www.x2i4eva.com

Profile Information

  • Gender
    Not Telling

x2i's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, not sure if this is posted in the right place (think it should be in the Regex section ) but hopefully someone can help me out a bit. I have the following string for example which is stored in a variable called $var. I wish to extract only the number after the equals sign and store it as a variable. So I am using the following code to do so: $ref_num = preg_replace("/.*?\[ref\=(.*?)\]\[\/ref\].*?/is", "$1", $var); The only problem is, I can omit the text before the integer and the tags themselves but I still get the text after the [/ref] section and I cannot get rid of it. It seems my .*? placed after it doesn't work like it does at the beginning. Can anyone offer any help at all, it will be greatly appreciated - I'm fairly new to using Preg_replace so I still don't know how best to form Regular Expressions. Thanks, Dan EDIT- I have found a workaround which I will post below - however I would still like to solve it the way I planned originally which is the way I posted here. Here's what I did - because I know the integer is never going to be more than 5 characters long, I used the replace from before but added a substring like so. $ref = substr(preg_replace("/.*?\[ref\=(.*?)\]\[\/ref\]/is", "$1", $var),0,5); This grabbed the first 5 characters whether it was a number or not, then I used this to strip any non-numerical characters. Finally I added an intval to convert it to an integer rather than a string. $ref = intval(preg_replace ('/[^\d\s]/', '', $ref));
  2. Hi, I am in a spot of bother with the way smilies are dealt with in PHPBB. I am using a function to convert BBCode into HTML where necessary by using preg_replace and it works fine, however I cant figure out how to use preg_replace to display the smilies when a user uses one. Here is the text that is output when a smilie is used: <!-- s:) --><img src="{SMILIES_PATH}/001.png" alt="" title="Smile"><!-- s:) --> I have been using the following although it is not working and I am wondering if someone can either point out where I have gone wrong or provide me with a solution to my problem - thankyou $var = preg_replace('/\<!-- .*? --><!-- sg src="{SMILIES_PATH}\/(.*?)" alt=".*?" title=".*?" \/><!-- .*? -->/is', '<img src="http://www.xboxresource.com/forum/images/smilies/$1" />',$var); -EDIT- I fixed it, I simply used the following to replace {SMILIES_PATH} with the actual url and it worked - sorry for wasting your time $var = str_replace("{SMILIES_PATH}","http://www.xboxresource.com/forum/images/smilies/",$var);
  3. Sorry for double posting since I cannot edit my post again ¬_¬ When I run it through this website: http://www.jslint.com/ I get this result... I don't know if this is what is causing it but still: Implied global: ActiveXObject 31, hova 2 19, req 7 9 10 13 23 24 27 28 31 32 33 36 37, results 10 11, window 22 30 Problem at line 45 character 16: Implied eval is evil. Pass a function instead of a string. jahtimer = setInterval('jah(\'chatget.php?limit=<?php echo $limit; ?>\',\...
  4. Hi, I have a code that refreshes a chat box every 10 seconds and it works an absolute treat in Firefox 3.5, however in IE7/8 it doesn't wish to co-operate. It doesn't reload the div and whats worse is that even hitting CTRL+F5 will refresh it properly - yet if you navigate to the page that holds the chat entries outside of the chat box it works - then when you go back to the chatbox it will reload. Can someone help me out if possible? <script type="text/javascript"> hova = false; var jahtimer; function jahDone(target) { // only if req is "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { results = req.responseText; document.getElementById(target).innerHTML = results; } else { document.getElementById(target).innerHTML = "jah error:\n" + req.statusText; } } } function jah(url, target) { if(hova === false) { // native XMLHttpRequest object document.getElementById(target).innerHTML = '<span class="ajah_waiting"><a href="java script:jah(\''+url+'\',\''+target+'\');"><br \/><img src=\"images/loadingchat.gif\" style=\"height:30px;width:30px;border:0;\" \/><br \/>Refreshing...<\/a><\/span>'; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = function() { jahDone(target); }; req.open("GET", url, true); req.send(null); // IE/Windows ActiveX version } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = function() { jahDone(target); }; req.open("GET", url, true); req.send(); } } } } function startInterval() { jah('chatget.php?limit=<?php echo $limit; ?>','chat'); jahtimer = setInterval('jah(\'chatget.php?limit=<?php echo $limit; ?>\',\'chat\');', 10000); } //function jah_switch(url, target) { //if (document.getElementById(target).innerHTML !== '') { //document.getElementById(target).innerHTML = ''; //} else { //jah(url, target); //} //} </script> <div id="chat" align="center"></div> The chat box can be located here: http://www.x2i4eva.com/chat.php
  5. Solved, you can go ahead and delete this if you want...
  6. I have a little bit of a problem, you see I have an iframe on my page - now the contents of the iframe can vary in terms of the contents total height. Now I use this JS to get the height of the div contents that is on the page: <script type="text/javascript"> onload = function() { var divh = document.getElementById('mydiv').offsetHeight; alert(divh +"px"); } </script> Now I was wondering if or how you can resize the iframe from within the iframes contents based on the iframes contents. I tried parent.document.getElementById('myframe').style.height = divh; but to no avail. The iframe has an ID of 'myframe' in case you're wondering. Thanks in advance for any help given.
  7. Not that it will make much sense to you but for the descriptions it was: Array ( [0] => Array ( [0] => (1,000) [1] => (1,000) [2] => (1,000) ) [1] => Array ( [0] => (60) [1] => (60) [2] => (60) ) [2] => Array ( [0] => (60) [1] => (60) [2] => (60) ) [3] => Array ( [0] => (50) [1] => (50) [2] => (50) ) [4] => Array ( [0] => (60) [1] => (60) [2] => (60) ) [5] => Array ( [0] => (60) [1] => (60) [2] => (60) ) [6] => Array ( [0] => (40) [1] => (40) [2] => (40) ) [7] => Array ( [0] => (30) [1] => (30) [2] => (30) ) [8] => Array ( [0] => (40) [1] => (40) [2] => (40) ) [9] => Array ( [0] => (40) [1] => (40) [2] => (40) ) [10] => Array ( [0] => (40) [1] => (40) [2] => (40) ) [11] => Array ( [0] => (40) [1] => (40) [2] => (40) ) [12] => Array ( [0] => (40) [1] => (40) [2] => (40) ) [13] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [14] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [15] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [16] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [17] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [18] => Array ( [0] => (30) [1] => (30) [2] => (30) ) [19] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [20] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [21] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [22] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [23] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [24] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [25] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [26] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [27] => Array ( [0] => (20) [1] => (20) [2] => (20) ) [28] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [29] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [30] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [31] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [32] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [33] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [34] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [35] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [36] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [37] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [38] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [39] => Array ( [0] => (10) [1] => (10) [2] => (10) ) [40] => Array ( [0] => (10) [1] => (10) [2] => (10) ) )
  8. None of the above worked i'm afraid although I have solved it myself using some of the methods you guys suggested. For those interested I did it this way: $all_icons = array(); $all_descs = array(); foreach ($descs as $desc) { array_push($all_descs, $desc[1]); } foreach ($icons as $icon) { array_push($all_icons, $icon[1]); } echo "<table>"; for($i=0; $i<count($icons); $i++) { echo "<tr><td><img src=\"" . $all_icons[$i] . "\" /></td> <td>".$all_descs[$i]."</td></tr>"; } echo "</table>"; Thanks for all your help guys... much appreciated. EDIT: I just read akitchin's reply and that worked a treat... thanks, a much shorter solution to the one I came up with.
  9. Basically without revealing too much I am using the following to get the html from a page on my website: $html = file_get_contents("mypage.html"); On this page is a list of images each with a description of the image next to it. I am therefore using the following to separate them both into an array: //Get Icons preg_match_all( '/<img id="image.*?" src="(.*?)">/s', $html, $icons, PREG_SET_ORDER); //Get Details preg_match_all( '/<span id="description.*?">(.*?)<\/span>/s', $html, $descs, PREG_SET_ORDER); Now the only way that works to output these is the following: //Output all icons foreach ($icons as $icon) { echo "<img src=\"" . $icon[1] . "\" /><br />"; } //Output all descriptions foreach ($descs as $desc) { echo "<b>" . $desc[1] . "</b><br />"; } However this just outputs all of the images in a vertical line and then all the descriptions, therefore I wanted to put it into a table so the images were next to the right descriptions.
  10. I tried that but unfortunately I just get the word Array for every entry... When I use this it works however I get all of the elements outputted at once so it's hard to add the tr and td tags in between: foreach ($icons as $icon) { echo $icon[1] . "<br />"; } I then cannot do another similar for loop for the text at the same time as the above code...
  11. Yes both will have the same amount of items. I tried using the count() feature too.
  12. Hi, I am struggling a bit with 2 arrays being sorted into a table. Basically I have an array of images which has been filled using the preg_match_all() function and again, an array of text using the same method. My aim is to have two columns in a table, the left column being the images and the right being the text associated with the image. The problem is I can't loop through both the arrays at once. Can anyone help me out at all... if you need more specifics then ask and I will provide them. Thanks in advance for any help given.
  13. I used the following class to output the array: http://lauris.night.lt/forge/easy_scrobbler/ I'll give your solutions a shot, thanks EDIT: It worked thankyou guys
  14. Hi, I'm experiencing a little problem picking out specific values in an array that I have - I have used var_dump to out put the following but I cannot pick out the specific items I want: array(1) { [0]=> array(9) { ["ARTIST_MBID"]=> string(36) "329f95db-f02e-40bf-a5f7-0dea11529ce3" ["ARTIST"]=> string(13) "Enter Shikari" ["NAME"]=> string(11) "Juggernauts" ["MBID"]=> string(0) "" ["ALBUM_MBID"]=> string(0) "" ["ALBUM"]=> string(0) "" ["URL"]=> string(52) "http://www.last.fm/music/Enter+Shikari/_/Juggernauts" ["DATE_UTS"]=> string(10) "1240718080" ["DATE"]=> string(18) "26 Apr 2009, 03:54" } } I want to be able to get say the artist name and song name as strings. I have tried using foreach to no avail and because the arrays are embedded within one another I don't quite know how to do it, could anyone help at all? Thanks in advance...
  15. Hi, i'm new here and not sure if this is the right place but I hope someone can help or guide me in the right direction. To put it simply I have made a script for PHP using GD which designs someone's gamercard from XBOX at this address (using my gamertag as an example) http://www.x2i4eva.com/gdi?gamertag=x2i4eva Using the following on a webpage will work and display the image: <img src="http://www.x2i4eva.com/gdi?gamertag=x2i4eva" /> However, when posting on, say a forum, such a code will not work: [img=http://www.x2i4eva.com/gdi?gamertag=x2i4eva] When viewing the properties of the image it only returns the url of the page not the actual image that has been drawn so it is possible to get around this without having to save the image to the server? Thankyou for any help given.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.