Jump to content

LittleNicky

Members
  • Posts

    23
  • Joined

  • Last visited

Posts posted by LittleNicky

  1. Ok thanks guys but can I clarify a couple of things:1. Is it only the files with php code in that have to be .php files?2. Assuming the answer to 1. is yes, do I have to mention php in the <head>, eg "<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />", in this example 'content= "text/html..."'; should my <head> have some reference here to php?ThanksMike
    As far as I'm aware1. Yes2. It depends on the page. For example an index page will need it to appear somewhere if your output from the php is html.
  2. It wouldn't be that difficult to make a demonstration of how it works. If people would actually read it instead of asking questions about the same thing I might be persuaded to do one.
    I would read it! In fact I did!Check out TutorialI felt this was very basic. It requires you to work a few things out, which was very frustrating! But now I've worked thorugh it and I understand it all and have changed and expanded it.By the way is it worth using more random variable names like using colors etc just to prevent hackers?
  3. Well, the first step is to select which fields you want (or use * for all of them). Your sql so far is:SELECT field1, field2,etc FROM table_nameORSELECT * FROM table_nameThen you have to make sure it is sorted correctly by using the order by command and then ASC or DESC for ascending or descending. As you want most recent first I think you should try DESC:SELECT * FROM table_name ORDER BY date_field DESCThen you want to limit the results to the first 8 rows so the LIMIT keyword seems a good one to use:SELECT * FROM table_name ORDER BY date_field DESC LIMIT 0,7This returns all rows between 0 and 7 (ie 8 rows). Don't forget that your first row is 0 (not 1).
    Exactly what I wanted, cheers!
  4. My advice to you is to get an open source like phpBB, install it and work with it (adding modifications etc.). That is one of the best ways to learn as you get a feel for PHP, instead of looking at half-done code.- Moridin
    Mate, I get where you're coming from, but I tried that and phpBB is far to complicated to pick up and modify for a beginner. I'm a beginner, I tried it and it almost put me off php as I got too overwhelmed.Good to hear that people are willing to help! I'm currently in the process of building my first php site. I have a half decent blog page set up, with a login and admin section. The user profile is next, then the photo gallery, then I might consider the forum. I've got that addicted that I'm thinking about it all day at work. Wish I had more time to dedicate to it. :-(
  5. If you clicked on a link to get to the login page, then you would redirect to the referer. The referer for a page is the page where you clicked on a link to reach the current page. I believe that is in $_SERVER['HTTP_REFERER']
    OK cool, so would the code be header(Location: $_SERVER['HTTP_REFERER']); ?
  6. How do I set the date & time (in one field) automatically as the current date & time when I'm inserting into a field? Also what should I have the field set as in the mySQL database?

  7. Ok so I've finally admitted divs seem to be the way forward where data is not stored.So whats the best way to create a menu using divs? A menu that has each link on top of each other but nicely spaced. Each menu item background must be the same length!

  8. You can use the nl2br function to convert all newlines to br tags automatically:http://www.php.net/manual/en/function.nl2br.phpAs for the regular expression code:The first thing he does is set up two arrays, a "search" array and a "replace" array. The preg_replace function takes both arrays, and the target string. When two arrays are pased to preg_replace, it will replace the first search element by the first replace element, the second search element by the second replace element, the third search element by the third replace element, etc. So the first search element:'/\[b\](.*?)\[\/b\]/is'Which is a regular expression to find all cases of bold tags, gets replaced with the first replace element:'<strong>$1</strong>'Which of course converts it into "<strong>" tags. The $1 is a "backreference", meaning that the $1 gets replaced with the first match from the search pattern. In practical terms, that means that whatever text is between the bold tags will be inserted into the replacement pattern.If you look through the search array, you can see that it finds bold, italic, underline, video, image, strikethrough, object, font, url, code, quote and many more bbcode tags, and replaces them with their corresponding HTML equivalents. It should also be noted that this will also replace all newlines with br tags, so if you use this function as well as nl2br, you will get 2 br tags for every newline (if you use nl2br first since nl2br leaves the newlines, but this function will replace the newline with the br tag).This is actually a very handy function, and is probably exactly what you're looking for.
    It does look like what I want. I'm having trouble implementing it tho.At what point might I use the function? I assume I have to apply it to the input of the textarea, but how?
  9. I am not sure about the constructor, but it may be this:SELECT * mytable WHERE {$a_php_variable}=(field1 + field2)This doesn't concatenate the fields, but checkes a value against the values of the one field glued to the value of the other. It can be like this too:SELECT * mytable WHERE field1 + field2 = '{$a_php_variable}'Which looks more logical :)
    Ok so would this work:SELECT * mytable WHERE firstname + " " + lastname= '{$fullname}'if $fullname equals 'firstname lastname'
  10. Hi,Does anyone know how I concatenate 2 fields together?For example I want to say "SELECT * mytable WHERE a_php_variable='field1 concatentated with field2'"

  11. \n into <br />?
    $post = str_ireplace("\n", "<br />", $post);

    That changes every line break into <br />, that works if you have a text area. You can't even write \n in the text box to make a <br />, it is automatically converted to PHP format. :)

    Ok cool, so do i put all of these into a php file then include them the relevant pages?
  12. I made my own forum engine once, pure PHP + MySQL... It's very simply though :) . You could just post posts and threads and read them. You could login and register. Posts had simple formatting (bold, italic, underline, strikethough, font alter, color alter, header, hr [actually, a table with ::: text in th] and smilies [i borrowed these here]). Also you could change your password. Now I'm adding a search engine to it (won't be hard). Also I never distributed it, it was private.My technique to change BBcode-like code (like , , [Tahoma], [Purple]) to HTML was the str_replace() function... like this was the code to change to <b>.
    $post = str_replace("[B]", "<b>", $post);$post = str_replace("[/B]", "</b>", $post);

    Note it was also case-sensitive! :)You wouldn't even edit your posts... that's under work too.

    So this sort of thing would be implemented by having a 'bold' button which inserts a "B" before and a "/B" after my text that I've selected. Is that correct? So what about inserting a <br>? Users would not want to click a button on the screen every time they want a new line.
  13. Regex is the answer my children
    function bb($str){	$str = htmlentities($str);		$search = array(								'/\[b\](.*?)\[\/b\]/is',								'/\[center\](.*?)\[\/center\]/is',															'/\[i\](.*?)\[\/i\]/is',							   								'/\[u\](.*?)\[\/u\]/is','/\[video\](.*?)\[\/video\]/is',								'/\[move\](.*?)\[\/move\]/is',								'/\[img\=(.*?)\]/is',								'/\[hr\]/i',								'/\[s\](.*?)\[\/s\]/is',								'/\[o\](.*?)\[\/o\]/is',								'/\[font\=(.*?)\](.*?)\[\/font\]/is',								'/\[url\=(.*?)\](.*?)\[\/url\]/is',								'/\[url\](.*?)\[\/url\]/is',								'/\[img\](.*?)\[\/img\]/is',								'/\[img w\=(.*?)\](.*?)\[\/img\]/is',								'/\[sup\](.*?)\[\/sup\]/is',								'/\[sub\](.*?)\[\/sub\]/is',								'/\[tr\](.*?)\[\/tr\]/is',								'/\[td\](.*?)\[\/td\]/is',								'/\[table\](.*?)\[\/table\]/is',								'/\[tr (.*?)\](.*?)\[\/tr\]/is',								'/\[td (.*?)\](.*?)\[\/td\]/is',								'/\[table (.*?)\](.*?)\[\/table\]/is',								'/\[code\](.*?)\[\/code\]/is',								'/\[email\](.*?)\[\/email\]/is',								'/\[email\=(.*?)\](.*?)\[\/email\]/is',								'/\[quote\](.*?)\[\/quote\]/is',								'/\[quote\=(.*?)\](.*?)\[\/quote\]/is',								'/\n/i'								);		$replace = array(								'<strong>$1</strong>',								'<center>$1</center>',								'<em>$1</em>',								'<u>$1</u>','<object width="425" height="350"><param name="movie" value="$1"></param><embed src="$1" type="application/x-shockwave-flash" width="425" height="350"></embed></object>',								'<marquee>$1</marquee>',								'<img src="$1" />',								'<hr />',								'<span style="text-decoration:line-through;">$1</span>',								'<span style="text-decoration:overline;">$1</span>',								'<span style="font-family:$1">$2</span>',								'<a href="$1" target="_blank">$2</a>',								'<a href="$1" target="_blank">$1</a>',								'<img src="$1" />',								'<img src="$2" width="$1"/>',								'<sup>$1</sup>',								'<sub>$1</sub>',								'<tr>$1</tr>',								'<td>$1</td>',								'<table>$1</table>',								'<tr $1>$2</tr>',								'<td $1>$2</td>',								'<table $1>$2</table>',								'<b>Code:</b><br /><table class="code"><tr><td class="code">$1</td></tr></table>',								'<a href="mailto:$1">$1</a>',								'<a href="mailto:$1">$2</a>',								'<table width=\'60%\' align=\'center\' border=\'1\' bgcolor="#999999"><tr><td><b>Quote:</b></td></tr><tr><td width=\'100%\'><i>$1</i></td></tr></table>',								'<table width=\'60%\' align=\'center\' border=\'1\' bgcolor="#999999"><tr><td><b>Source: $1</b></td></tr><tr><td width=\'100%\'><i>$2</i></td></tr></table>',								'<br />'								);		$str = preg_replace ($search, $replace, $str);					return $str;	};

    It looks impressive, but any chance you can explain what's going on here?
  14. What I mean is not to allow entrance of pure HTML in a text area. You could use BBCode as this forum does or create some sort of white list, that is, HTML elements that can be entered, and not allow the user any further modifications. If you choose the BBCodes approach, you must also convert special symbols to entity codes like for example "<" to "<" etc.
    That's what I needed! Now how do I implement that?
  15. And I must say that if that's the case: that's the worst idea ever. You're practically begging hackers to inject malicios JavaScript there.
    So lets say I want to create a blog. The user will have a text area to type their blog in, but when they press enter it appears to start a new line. But when they submit the blog and view it, it's all one block off text. This is what I'm trying to avoid. What would you suggest?
    If that's all you want to do, you can use nl2br to convert newlines to "\n<br />".
    Whats nl2br?
  16. I think he refers to
    <strong>some</strong> text

    Being rendered asAnd I must say that if that's the case: that's the worst idea ever. You're practically begging hackers to inject malicios JavaScript there.

    Yer as boen said it. Things like if I want to start a new line I press enter rather than typing <br>
×
×
  • Create New...