Jump to content

joe92

Members
  • Posts

    304
  • Joined

  • Last visited

Posts posted by joe92

  1. Hey, thanks for the response. That almost worked. It gave the buttons the wanted 20% gap between them, however floats the buttons together with the gap to the left now instead of in the center. With much playing around, I couldn't force it to sit in the center. Would you be able to explain how the following CSS class works to me please?

    .center input, .center p {
    float:left;
    }

     

     

    I found a workaround however. It is to place the buttons in a div which has a set width, I have found 35% looks nice, and to give the div margins left and right auto. I then float the buttons inside, one to the right, and one to the left. It gives the desired effect. It looks like this now, html:

    <div class="mainContent">
    Text, text and then some.<br/><br/>
    <div class="widener centered">
    	<input type="button" class="floatR" value="No" /><input type="button" class="floatL" value="Yes" />
    </div>
    </div>

    CSS:

    .centered{
    margin-right:auto;
    margin-left:auto;
    }
    .floatL{
    float:left;
    }
    .floatR{
    float:right;
    }
    .widener{
    	width:35%;
    }
    

     

    Thank you for your help haku

     

    Joe

  2. I think this is going to be very simple but it is just illuding me right now. What I want is to have two buttons in a form centered on their own line and equally spaced out between them by 20% of the parent div. Like so:

     

    ----------------------------------------------------------------------------------------------------

                                      [button]<-- 20%--> [button]                           

    ----------------------------------------------------------------------------------------------------

     

    With the space on the other sides variable to whats left. This is my code so far, html:

    <div class="mainContent">
    Text, text and then some.<br/><br/>
    <div class="center">
    	<input type="button" value="Yes" /><p class="widener"></p><input type="button" value="No" />
    </div>
    </div>

    CSS:

    <style type="text/css">
    .mainContent{
    width:70%;
    border:solid 1px #000;
    }
    .center{
    text-align:center;
    }
    .widener{
    display:inline;
    width:20%;
    }
    </style>

     

    Is there a way to do this without using tables? I would like the gap to be 20% as the div that it is positioned in is relative to the size of the window.

     

    Cheers,

    Joe

  3. $word = 'numbers';
    $numbers= array('1', '2', '3', '4');
    
    echo $$word[0];

     

    I expected the output to be '1'. It ended up being nothing...  :-\

     

    Why does this not work? Is it not possible to have a variable variable array? And if not, is there a workaround?

     

    Cheers,

    Joe

  4. Ahh, I was going about this the complete wrong way! Got it working now:

     

    function randomNumLet($amount){
    $theNos = array('1', '2', '3', '4', '5', '6', '7', '8', '9');
    $theLet = array('a', 'b', 'c', 'd', 'e');
    $combo = '';
    for($i=0;$i<$amount;++$i)
    	{
    		$num = count($theNos);
    		$rand_num = rand(0, ($num - 1));
    		$let = count($theLet);
    		$rand_let = rand(0, ($let - 1));
    		$combo.=$theNos[$rand_num].$theLet[$rand_let].'~';
    	}
    return $combo;
    }
    
    
    $num_let = randomNumLet(2);
    echo $num_let;

     

    Its now counting the array and generating a random number between 0 and the size of the array - 1. Sorted,

    Joe

  5. Well, got it solved. Try this, it works:

     

    $message = "
    <br/>
    <br/>
    <br/>
    I said https://www.google.com<br/>
    I said http://www.google.com<br/>
    I said www.google.com<br/>
    I said http://google.com yeah<br/>
    I said www.google.co.uk maybe<br/>
    I said ftp.google.co.uk<br/>
    I said http://ftp.google.co.uk<br/>
    I said http://google.co.uk";
    
    $message1 = preg_replace("/(?<!href=\")((https?:\/\/)(www\.|ftp\.)?[\w\-]+\.[^\s\<]+)(?!\")/ism", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $message);
    $message2 = preg_replace("/(?<!http:\/\/)(?<!https:\/\/)((www|ftp)\.[\w\-]+\.[^\s\<]+)(?!\")/ism", "<a href=\"http://\\1\" target=\"_blank\">\\1</a>", $message1);
    
    echo $message2;

     

    Obviously those ftp addresses go nowhere though ;)

     

    The first preg_replace gets every link with a http:// before it but maybe not with a www so that means it grabs:

    http://www and

    http://

     

    Which meant that the only way left to write a link is:

    www.

     

    That means the second regex should only search for those with www and should in fact make sure it does not start with http or https. Since a lookbehind has to be fixed length that meant sticking two lookbehinds in the second regex. Anyway, tis solved now. Posting this explanation should anyone chance upon this in the future.

     

    Take care,

    Joe

  6. I am trying to make a function that will generate a random number letter combo but the letters can only be abcde, no others. It must come out in the format, 1a~3d~9b~ etc. This is what I have so far:

     

    function randomNumLet($amount){
    $theNos = array('1', '2', '3', '4', '5', '6', '7', '8', '9');
    $theLet = array('a', 'b', 'c', 'd', 'e');
    $combo = '';
    for($i=0;$i<$amount;++$i)
    	{
    		$rand_num = array_rand($theNos, 1);
    		$rand_let = array_rand($theLet, 1);
    		$combo .= $theNos[$rand_num[0]].$theLet[$rand_let[0]].'~';
    	}
    return $combo;
    }
    
    
    $num_let = randomNumLet(2);
    echo $num_let;

     

    And it returns just '~~' with no numbers or letters. I'm a bit stuck here and would appreciate any help. How can I make the function output 1a~4d~ etc?

     

    Cheers,

    Joe

  7. Hang on, I'm so used to using heredocs I forget everything on my file is within php tags already. Variables always need to be called from within php tags. Ugh, so stupid of me. Ignore my previous post :facepalm:

     

    How are the ID's for the table rows being set? They will need to be unique for the javascript to move only one at a time.

  8. This looks wrong to me:

    <tr id="tableItem<?=$id;?>">

     

    It should be something more like:

    <tr id="tableItem=$id">

     

    Where $id is set before in php. When calling a variable it needn't be called from within <?php ?> tags, it just needs to be set from within them.

     

    Could you provide the entire html table code please? I only see one row there...

     

  9. Ok, I think I know what is happening. The first regex turned it link into an <a> tag with the contents as the name of the website. So when the second regex was run it saw the hyperlink in the middle of the tag and converted that. But on that premise it should have ended up going like so should it not which wouldn't explain the <a> tag within the href:

    link:
    http://www.google.com
    
    First regex into:
    <a href="http://www.google.com">http://www.google.com</a>
    
    Second regex into:
    <a href="http://www.google.com"><a href="http://www.google.com">http://www.google.com</a>

     

    Ahhhh no, I see now. The second regex is saying the http can be there or not be there so it read the href and didn't continue with the regex but then saw the www. which it can start with as long as it doesn't begin with the href but it didn't so it continued. Ha. Sorry about all this dialogue. I just figured it out as I was writing it. Now to get around that...

  10. Hi there, I am baffled by this.

     

    I have two preg_replaces running to account for almost every type of hyperlink on a page and in each is a lookbehind to make sure the hyperlink is not prefixed with 'href=' as that would indicate that it has already been run through a different preg_replace and placed in an <a> tag. Here are the regex's:

    $message = preg_replace("/(?<!href=\")((https?:\/\/)(www\.|ftp\.)?[\w\-]+\.[^\s\<]+)(?!\")/ism", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $message);
    $message = preg_replace("/(?<!href=\")(https?:\/\/)?((www|ftp)\.[\w\-]+\.[^\s\<]+)(?!\")/ism", "<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $message);

     

    They both work OK except that the lookbehind doesn't seem to work:

    Input:
    http://www.google.com
    www.google.com
    http://google.com
    www.google.co.uk
    http://google.co.uk 
    
    Output:
    <a href="http://<a href="http://www.google.com"" target="_blank">www.google.com"</a> target="_blank"><a href="http://www.google.com" target="_blank">www.google.com</a></a>
    <a href="http://www.google.com" target="_blank">www.google.com</a>
    <a href="http://google.com" target="_blank">http://google.com</a>
    <a href="http://www.google.co.uk" target="_blank">www.google.co.uk</a>
    <a href="http://google.co.uk" target="_blank">http://google.co.uk</a> 
    

     

    It would appear that because the first one can be run by both preg_replace's, it is being. Does anybody know why this is happening? Even with the lookbehind. I thought I had it all working, but it seems like I was wrong.

     

    Thank you for your help

    Joe.

  11. Oh wow, glad you spotted that! I thought I had it all sorted for my forum, I clearly hadn't done a thorough testing. The following almost works except for the second part runs the regex again on the third hyperlink. I'm not sure why this is and am going to have to sort this out later. Replacing just google.com does not work (and I don't think it does in many forums) but could possibly be added by searching for a mixture of characters that finishes with .com or .co.uk etc.. I'll be working on this regex tonight so I'll let you know when it is properly working. What I did so far was to remove the caret which was making it only look for links at the beginning of the block of text.

     

    <?php
    
    $message = "Why not visit www.google.com or google.com or http://www.google.com or http://google.com or www.google.co.uk or http://google.co.uk ";
    
    $message = preg_replace("/(?<!href=\")((https?:\/\/)(www\.|ftp\.)?[\w\-]+\.[^\s\<]+)(?!\")/ism", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $message);
    $message = preg_replace("/(?<!href=\")(https?:\/\/)?((www|ftp)\.[\w\-]+\.[^\s\<]+)(?!\")/ism", "<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $message);
    
    echo $message;
    
    ?>

  12. Here's a discussion with myself as I went down this path. Go to the last post for a preg replace that works on a random url link ;D

     

    http://www.phpfreaks.com/forums/index.php?topic=336117.0

    (You don't need parts 1-4 as they deal with url links enclosed in bb code)

     

    You will also need the following line after prt5;

    $replaceUrlPrt6 = preg_replace("/^(?<!href=\")(https?:\/\/)?((www|ftp)\.[\w\-]+\.[^\s\<]+)(?!\")/ism", "<a class=\"nWhite\" href=\"http://\\2\" target=\"_blank\">\\2</a>", $replaceUrlPrt5);

     

    This is so that you can have addresses that start with or without http:// or with or without www. but need at least one or the other

  13. The forward slashes are delimiters. The are used to contain the bounds of the pattern. There are several types of delimiters including ~ and %. They each have different pro's and con's and I don't claim to understand the differences between them all.

     

    The s after the closing delimiter is a pattern modifier. Heres a list of all the modifiers available and their meanings.

     

    p.s. Mark the topic as solved ;D

  14. The [] means character class. It can be a range of characters, i.e. [0-9] which will match a digit from 0-9, or it can be individual sets of characters, [abc] which will match a or b or c. As the dash means range, you have to escape it with \-. However, the < sign and the > sign do not need to be escaped if placed within a charater class. Heres some more info on that. That guide is gold, do read it if you get some time, but especially read that section to understand which metacharaters need to be escaped within character classes.

     

    if(preg_match('/[<>\-]/s', $this->Results->Text))

     

    I don't know in what enviroment you are using it in and I haven't tested it so let me know if it doesn't work.

     

    Hope this helps,

    Joe

  15. Why do you need these characters to be prevented from being put into your textfield? If it is because you don't want them ending up in your database, there is a built in function called htmlspecialchars and another called htmlentities which will make those characters and more safe for you.

     

    If its for another reason, please provide the code you have already tried, i.e. the full pattern, so we can help you :)

  16. If you truly understand the subject then you should be able to teach your peers in class when they get stuck. Once you are comfortably teaching at the same time as the teacher, she might notice this and start giving you more advanced things to do instead of what everybody else is doing (this happened to a friend of mine in my German lessons when I was at school).

     

    Or she will ignore you and you will just have to grin and bear it. In which case, do the assignments as quickly as possible and then start experimenting in whichever language you like best. She can't complain if you have done the work!

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