Jump to content

joe92

Members
  • Posts

    304
  • Joined

  • Last visited

Posts posted by joe92

  1. The flag for any number is \d :)

     

    You should refrain from doing repetition once, {1}, or placing a character class round a single character, [-]. They really are pointless and just mess up your pattern making it harder to bug find.

     

    The website I linked to in my previous post is a brilliant tutorial on regular expressions. If you don't understand something about them, like lookbehinds, then just read what it says. You'll find it helps.

  2. I'm slightly confused by what you mean, is it turn = into == but only if it is not part of another operator, i.e. >=?

     

    $str = preg_replace('/[^\<\>][\=]{1}/m', '==', '5x11=8x11.5&6.3=6.3');
    

     

    This part first, just for future reference, can be neatened up quite a bit. You don't need to escape those signs inside the character classes. Just the signs ']', '\', '-', '^' and whatever the closing delimiter is need to be escaped if using literally. Read the paragraph, 'Metacharacters Inside Character Classes', here.

     

    The repetition of 1 is also superfluous. You can just get rid of it. You also don't need to add a character class round a single character, =, you can remove that too. That makes the expression quite a bit easier to read:

     

    $str = preg_replace('/[^<>]=/m', '==', '5x11=8x11.5&6.3=6.3');
    

     

    The reason the preg_replace is failing for your needs is because it is matching the symbol before the equal sign rather than just checking whether it exists or not. To fix this you need to use a negative lookbehind.

     

    A lookbehind (or lookahead) checks whether or not a character exists in the string but doesn't include it in the match. In this case we want to make sure the characters < or > do not exist before the equal sign. An annoying thing about the lookbehind is that is has to be of fixed length (a lookahead can be of unfixed length). This has tripped me up many a time in the past but I don't think that should be a problem here as it doesn't class alternation as varying length.

     

    Meaning we can use:

            $str = preg_replace('/(?<!<|>)=/m', '==', '5x11=8x11.5&6.3=6.3');
    

     

    See it working here, http://codepad.viper-7.com/JUYovq.

     

    Hope that helps you,

    Joe

  3. That sounds like an avenue to explore, unfortunately some of these websites are written purely in HTML with CSS and JS so it can't be implemented here.

     

    I'm thinking the iframe route it going to be most effective. I just can't think of a way to get the data to a HTML page any other way.

     

    Thanks for your help.

    Joe

  4. I always thought that Google operates on a database type system, wherein the websites are indexed along with other data such as clicks and views and would be searched via the database. This would mean that the cache was an extra but not essential to the workings of the whole system. Although saying that, I am aware that for SEO it's always good to view the cache, and then the plain text file so that you can understand which links are crawled. Thankfully though, that's not my job ;D

     

    We deliver the data through a quick ajax request on page load. The data is so small, usually less than 1 kilobyte, that there is no lag in seeing the page load up. The only problem is that Google does not cache this data (all the sites are listed though). I think that is because it reads as plain text hence ignoring JavaScript, but I'm not too sure as Google is immensely complicated.

     

    What solution would you suggest for this? Currently, we provide data for about 5 websites so a complete overhaul now is going to be much preferable to a complete overhaul in a months time or even later. What we are thinking at the moment is using iframes and storing the data in small HTML files for the iframes to read which we can post through ftp to the clients server if needed.

     

    Joe

  5. Just recently my colleague emailed me rather concerned that a website we provided data for wasn't getting cached by Google properly. I've just spent the last half an hour thinking of a way to solve the problem before coming to an annoying question in my head, which is:

     

    What is the point in Google cache?

     

    I can see the need for it when regarding static informative websites such as Wikipedia. Being able to view the content if Wiki goes down could come in handy. But when regarding a small dynamically changing website, is there a need to worry about the cache?

     

    The data on this website changes on a very regular interval, probably a minimum of once a week. I cannot think of any purpose for google cache other than to view content on a website when said website is down. In fact, I personally have never actually viewed a cache of a website other than this morning after getting the email. Is there some other purpose to the Google cache that I'm missing? Such as related to helping Google categorise, index and retrieve your site?

     

    There is all this hype around creating a website perfect for Google's crawlers that we're spending more time worrying about Google than the actual damn site. Haha.

     

    Cheers,

    Joe

  6. Is this what you mean?

     

    <?php
    
    $testInput = 'Hello, here is my number, 01911222333, or is it 0175522114, or even the mobile, 07520111444...';
    
    /*the preliminary check to see if there is a phone number*/
    if(preg_match("/0(1\d{8,9}|7\d{9})/", $testInput)){ 
    
    /*now match the phone numbers*/
    preg_match_all("/0(1\d{8,9}|7\d{9})/", $testInput, $phoneNumberMatches);
    
    /*do with it what you will*/
    print_r($phoneNumberMatches[0]);
    }

     

    Here it is in action: http://codepad.viper-7.com/OVa6jq

  7. This is a much debated topic, and patent law on software varies greatly from country to country. The US grants all software patents, along the lines that 'Everything under the sun made by man is patentable'. Whereas, over here in the UK, software patents are near impossible to get. In researching/applying for one here you will undoubtedly be referred by a solicitor to the 'Aerotel v Telco and Macrossan' case as they themselves don't have a clue.

     

    Let's say you invented facebook and you wanted to apply for a patent on the news feed. In the aspects of your patent, you described the layout of the news feed. You have a textarea at the top of the page to add your own news too and below it, all the news from your friends is displayed. Then, as patent law requires it, you go on to describe every detail of how this is achieved. How the database handles incoming data, how javascript manipulates the page to make it look 'real-time'. The whole works. Someone could then come along, read your patent and understand how to make an exact replica of it (as is the entire aim of patents). Then they do. But they put the textarea at the bottom of the page, and your friends news in a div above it (like text messaging on a smart phone). Because you had described the layout in your patent application, they are not actually infringing on the patent per se. Also they used two queries where you had used a left join? Just simple little things like this make infringements hard to prove.

     

    This is where it turns into a battle of the bank accounts. If you had enough money, you could take them to court. They would then have to defend themselves. If they won, you could then appeal the decision and take them right back to court. This can go on and on and if you don't have enough money, it will bankrupt you.

     

    So, in my opinion, patents on software are worthless. Unless that is, you want one to pretend that you're a 'big-fish'. And this, in my opinion, is a perfectly justifiable reason. If you stick 'Patent Pending' on your website, most 'little-fish' will see this and think you are not worth the hassle. Alongside registered trademarks and copyright symbols everywhere, they won't rip you off.

  8. Ok, I have located the problem and it was nothing to do with CSS or HTML. Somehow the message was being run through nl2br twice. I don't even know where the second call is yet. This just adds a bit more confusion but at least the problem is no longer a problem. :)

     

    Joe

  9. I have a div which is too display text and preserve the white space at the same time. I am using the css declartion white-space:pre-wrap; and setting a width on the div to achieve this. However, if the person enters a newline and submits this, when it is converted to a break line with nl2br and then displayed on screen it is far too big. I have absolutely no idea what is happening. I have attached an image of an example text to demonstrate what is happening.

     

    This is the HTML layout:

    <div id="theMessage$id" class="theMessage">
        <div id="pre$id" class="preTag">$message</div>
    </div>

     

    This is the CSS attached too it:

    .theMessage{
    position:relative;
    display:table-cell;
    padding:0 0 0 5px;
    margin:0;
    }
    .preTag{
    line-height:1em;
    margin:0; padding:0;
    min-width:53em; width:53em; max-width:53em;
    white-space:pre-wrap;
    white-space: -moz-pre-wrap !important; /* 1999+ Mozilla  */
    white-space: -pre-wrap;                /* Opera 4 thru 6 */
    white-space: -o-pre-wrap;              /* Opera 7 and up */
    word-wrap: break-word;                 /* IE 5.5+ and up */
    }

     

    Thanks for any help!

    Joe

     

    P.s. This is the html markup copied and pasted from firebug of the message from the attached image:

    <div id="theMessage911" class="theMessage">
    <div id="pre911" class="preTag">
    Here is a large paragraph of text to demonstrate how the newlines are too large. I have no idea what is causing the newlines to become so large but I have a feeling it is the fact that we are preserving white space by using the css, white-space:pre-wrap;. If I now end this paragraph and press enter once the gap will be too large.
    <br>
    See? I only pressed enter once. This is really beginning to annoy me. I have tried all sorts of fonts and the problem remains. I have line-height:1em; within my css also. What is happening?
    </div>
    </div>

    post-108745-13482403434231_thumb.png

  10. <?php
    //get the messages from the database
    $messagesID_query = mysql_query("SELECT
    				messageID, posterID, messageTime, message
    			FROM
    				chat_messages
    			ORDER BY
    				messageTime DESC
    			LIMIT
    				5
    		");
    

     

    I am currently using the above query to get the last 5 messages from a message log. Say we have 45 messages, the query will pull them out like so:

    45,

    44,

    43,

    42,

    41

     

    I then need that order flipped so that I can display the newest message (id, 45) at the bottom of the message box by simply accessing it last. Like so:

    41,

    42,

    43,

    44,

    45

     

    Is there a way I can do all of this in one go with mysql with no need to use any php functions afterwards? I am currently using two loops. One to reverse the order, and another to print the messages in the desired fashion.

     

    Many thanks,

    Joe

  11. That is possibly the best $ to GB ratio SSD around at the moment that I have seen. Get it. I installed a 60GB OCZ SSD (this one to be precise) as a primary drive in a computer for a colleague of mine and the speed increase is phenomenal. SSD's might be expensive but when you can get from stone cold off to checking your emails within 30 seconds, it soon pays off I think.

     

    However, if you're looking to save a bit of money, do as I did for my colleague. I installed the cheaper 60GB SSD for him as the primary drive and then a 500GB HDD (half the price of the SSD) as a secondary drive. The operating system and all programs are installed on the SSD and all the files are saved to the HDD. The computer is incredibly fast.

     

    Then again, if you aren't too bothered about saving money and want a really fast computer, you could still run that set-up described and then spend the money you saved (plus a little extra) on an intel i7-2600k CPU.

     

    But yeah, that is definitely a good SSD you have found. Comes in at just over a dollar a GB, which for an SSD these days is very good value. Also, I know for a fact that Corsair are one of the best for producing RAM, so it goes to say that they should also be good for SSD's. They're practically just large RAM chips ;)

     

    Joe

  12. I found it at long last! Haha. Though would love to see this implemented nonetheless :D

     

    By the way, I found a bug whiles searching for my post.

     

    If I were to enter the search term, 'mysql as', and select 'Match any words' it will mess up the search term highlighting. Something like this will be shown in a title somewhere.

     

    MySQL Help / ass="highlight">mysql SELECT not working.

     

    The as is matching in class, but only on topics that included mysql in them too. Presumably because it matches mysql first, then runs through 'as' and finds it in the class="highlight".

     

    Thought you'd want to know,

    Joe

  13. Can we have a way to filter our own posts by board? There is already a statistic to tell us how many posts we have in each separate board, but no way to view said posts.

     

    I ask this because I was just trying to look up a post I made a fair while ago in the MySQL Help board but cannot for the life of me remember what it was called.

     

    I tried using the search option, filling in the word 'the' and filling in the by user 'joe92' but was told:

    Your search query contained too trivial words. Please try again with a different query.

     

    Seems a bit overkill to limit searches if they filled in a particular user. Though totally understandable having that there if the search is searching by all users. Maybe remove that limitation when a user is filled into the search criteria?

     

    Cheers,

    Joe

  14. An excerpt from this forum found through this yahoo answers thread:

     

    If I return to my car whilst the ticket is being issued but drive off before it can be either handed to me or fixed to the vehicle am I still liable?

     

    This depends on who it is issuing the ticket.

     

    If it is a council parking attendant then, to be valid, the ticket must be either handed to the driver or fixed to the vehicle. If you subsequently get a Notice to Owner you should write to the issuing council, explaining the situation, and ask for it to be cancelled. If they will not cancel it then appeal. Although the adjudication services do not categorise types of appeal anecdotal evidence suggests that between a third and a half of all appeals are for this reason.

     

    However, if you return to find a police officer or traffic warden in the process of issuing a ticket then, if you drive off, the ticket can be sent to you as they enforce under different legislation.

     

    So in other words, if it's just a council parking attendant at a car park or likewise, then get in and drive like hell ;D

  15. Built to withstand the 'ardest conditions known to man.

     

    ayepad-228.jpg

     

    For non British people, some people (mostly farmers) in Yorkshire actually speak like the phonetic pronunciation of those words. Haha.

  16. Ok, well I am confused. Run this:

     

    <?php
    
    $pagecontent = '<div class="infobox"><div class="infoboxtitle">this is a title</div><div class="infoboxtext">example text</div></div>';
    
    $pagecontent = preg_replace('#<div class="([a-z]+)">([^<]+)</div>#i', "[$1]$2[/$1]", $pagecontent, 1);
    
    $pagecontent = preg_replace('#<#i', "<", $pagecontent);
    $pagecontent = preg_replace('#<#i', ">", $pagecontent);
    
    echo $pagecontent;
    
    ?>

     

    And the result is:

    <div class="infobox">[infoboxtitle]this is a title[/infoboxtitle]<div class="infoboxtext">example text</div></div>

     

    Ahhhh, and as I typed it I just got why mine wasn't working. The central part is looking for anything that isn't <, meaning it fails because the next div starts straight away. Duh. And without checking the contents, you're never going to be able to match up the correct tags so mine will never work. I suggest you look into making a recursive preg_replace_callback where the callback checks the contents for any nested content and alters the search pattern accordingly. As Xyph said, you are going to need a parser.

     

    Good luck and if you get stuck, ask again!

    Joe

  17. You don't need to escape the forward slash in the replacement side. That is not causing the problem though, just thought I'd mention it.

     

    You also don't need to run 3 preg_replace's for what could be achieved in one. I notice that the code you want to change it too has the class name as the tag name, therefore the following will suffice for all three, and be quicker too:

    $pagecontent = preg_replace('#<div class="([a-z]+)">([^<]+)</div>#i', "[$1]$2[/$1]", $pagecontent);

     

    If you want the class name to be exact then change the ([a-z]+) after class= into (infobox(?:text|title)?) (edit: Forgot to make the or part of the capture non capturing, fixed it). It will still be captured in the first parenthesis.

     

    In what way is it returning nothing? Are you making sure that the input is correct?

     

    Hope this helps you,

    Joe

  18. If you really want to list every type of domain ending then here is a convenient list for you:

    http://www.iana.org/domains/root/db/

     

    But fair warning, this will take time to complete.

     

    Otherwise, I would suggest changing your code to look for a http:// or www. or the two together, followed by a dot and the central part (consisting of letters, numbers and dashes), followed by a dot and the tdl. The tdl can be one or two part, but can never contain a digit.

     

    Something like this:

    ~(https?://(www.)?|www.)[a-z0-9-]+\.[a-z]{2,5}(\.[a-z]{2,5})?~i

     

    But then again that will let through www.a.zzz. It's your call on this one. Speed vs accuracy. The big or statement will take time to read through and hence be slow, whereas my snippet will allow incorrect domains through but will be read in a much greater speed.

     

    Hope this helps you,

    Joe

×
×
  • 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.