Jump to content

SiriusB

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

SiriusB's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am not asking for this thing to be done for me. At no point did I ask for that nor did I imply it. I haven't even asked for any specific code. Read my post again. I asked a specific question about how best to compare a recordset from a database with data parsed from a file. I even gave pseudo-code as to the solution I thought of and have asked if this is a good way of doing it. If not, what is the alternative? I only mentioned the purpose of the script to give a background to my problem and why I need to do what I am asking for. I appreciate your input, but in this case you have made an incorrect assumption.
  2. I am trying to create a PHP script that reads in a file, parses it for the data I want and compares it to the data I have in a database. The data is points and ranking information for a Folding@Home Team. Every week someone creates a news item with points gained by each team member for that week and other info. This is done manually and takes a lot of time. I hope for my script to automate as much of it as possible. The script was to run as follows: Download and parse latest statistics into 2D array Compare usernames in array to usernames held in Database Any new usernames and their respective points/rank to be added to database Compare points in 2D array of each user to those held in database. Output username and points gained I thought I had a working script until I actually tested it on real data, and realised I missed something rather obvious - the order of usernames from the parsed file is not going to be the same order as in my database - due to people moving up and down the ranks. So i can't just get a recordset from the db and run a simple loop to compare it to the parsed data. I am not sure how to go about comparing the database information with the parsed data that works around the fact the data could be in any order. The only thing i can think of is: foreach item in $parsed_data_array query database for $parsed_data_array=>username if(number of results == 0) build new insert query for current username else continue I don't know if this works [haven't tested yet] but I can't help feel it is a little DB intensive. There could be up to 200 queries being sent to the database. This can be minimized by adding extra criteria, like ignoring inactive users of course. Is this a viable solution or is there a much better way of doing this? Sorry if anything is unclear. Just ask and I will explain further if required.
  3. How would that help? I need to add <p> tags to paragraphs. I want to preserve the line breaks [\n] as it allows for readable code. My original line of code manages this, but adds tags to every block of text, regardless of whether or not it has a tag. I need a regular expression that can match something like "\n\nSome text\n\n" but not "\n\n<tag>Some text</tag>\n\n" where <tag> is any other xhtml tag. There has to be a regular expression that can accomplish this. If it was just for forum posts or comments/blog entries using nl2br wouldn't be an issue, as the content is usually fairly short. However my site has quite a large amount of content and I would prefer this to be correctly marked up. Not only is it following standards it makes creating CSS much easier as I have something to target. As I said, I can't be the only person to want to produce fully semantic code.
  4. That didn't work either, I'm afraid. True it only put <p></p> tags around actual paragraphs, but it removed the line breaks themselves so the page source becomes unreadable. It also didn't solve the problem of <p></p> tags being put around other tags such as <code> and <h2> etc. I know I could probably add [p] tags to my BBCode, but that would mean writing new content would take just as long as writing the XHTML myself. The whole point of moving my site to PHP was to reduce the time it takes for me to add content I really, really want to avoid having br tags everywhere as it flies in the face of good semantic markup. There isn't a clever regular expression that can go "oh look, \n\n - I shall add <p> tags to that. But If I find "\n\n<some other tag>" I'll ignore it." is there? So come on regex pros...
  5. Anyone else got any ideas? Surely I am not the first person to want to do this!
  6. I am not sure how. I don't want to remove all the tags. I just need to find a way to only put <p> tags around actual paragraphs and leave text with <hx> and <code> tags alone.
  7. Hi there I have decided to store content for my website in a database. For most of the content formatting such as headers, code, bold etc I am using BB Code. To convert the BB Code to XHTML I use the function below if (!empty($string)) { $search = array( '#\[b\](.*?)\[/b\]#s', '#\[i\](.*?)\[/i\]#s', '#\[u\](.*?)\[/u\]#s', '#\[img\](.*?)\[/img\]#s', '#\[url=(.*?)\](.*?)\[/url\]#s', '#\[code\](.*?)\[/code\]#s' ); $replace = array( '<b>\\1</b>', '<i>\\1</i>', '<u>\\1</u>', '<img src="\\1">', '<a href="\\1">\\2</a>', '<pre><code>\\1</code></pre>' ); //convert BBCode tags to XHTML $xhtml = stripslashes(preg_replace($search , $replace, $string)); //preserve paragraphs by converting newlines and returns with <p> tags $xhtml = str_replace('<p></p>', '', '<p>' . preg_replace('#\n|\r#', '</p>$0<p>', $xhtml) . '</p>'); //output formatted string return $xhtml; } The BB Code part itself is working just fine. However, I would like to preserver my paragraphs, otherwise the text is unbearable to read. I know about nl2br but this I think is untidy and not very XHTML compliant. As you can see in the function above there is the following line: $xhtml = str_replace('<p></p>', '', '<p>' . preg_replace('#\n|\r#', '</p>$0<p>', $xhtml) . '</p>'); This line replaces line breaks with <p> tags. The results are good but there are one or two problems. The line of code matches any line breaks and ends up putting <p></p> around <hx>, <code> and pretty much any other tags. An example of what I am talking about is below: <p><h1>Title</h1></p> <p>This is some text</p> <p><code>echo "This is code";</code></p> Is it possible to modify the line of code to only match sections of text that don't already have tags? I would try myself but regex is a massive mystery to me and I am not 100% sure how that line of code works Any help is greatly appreciated.
  8. I am new to PHP, but I am familiar with OO Programming through Java and C#. There is nothing wrong with using classes inside other classes. It is a normal occurance.
  9. Whenever I try to add any HTML to a database it throws up errors. Usually whenever it comes across anything such as <div id="whatever">
  10. I have considered a database but MySQL can't store HTML [as far as I know] and the content of my site has all been marked up. Again, my CSS relies on this. Given the amount of content I think it would be poor practice to not mark up such a large amount of content - not least sections of text and code and headers. Is there a way of storing HTML in MySQL?
  11. Hi there. Well first of all, hello *waves* Right, down to business. I currently have a small website here: http://smp.aeternum.co.uk At the moment it is in XHTML and is static, apart from the contact page. However, I have found since publishing the site that I make lots of changes every few days. Normally this isn't a huge problem but occassionally I add extra pages/links and because of the way I have made the site, I have to update the code on each page. While musing over the best way to manage my site I came up with a few things I would like to add, such as a comments feature for each page [or just the Troubleshooting page] and some other features. So I thought I might as well change it over to PHP and stretch my new-found PHP skills. No I come to do it, I find myself stuck as to the best way to approach it. First of all I started with splitting the header, navigation and footer into their own .xhtml files and include them when necessary in one main smp.php file. This stops repetition of code and also makes it easier to make changes. The part I am stuck with is how to store and include the content. I have considered a MySQL database, but I think I would lose all the XHTML formatting [paragraphs, headers, code etc] so instead thought of putting the content into their own .xhtml files for inclusion. So now I have one .php file called smp.php which looks, roughly, like this: include ('header.xhtml'); switch ($_GET['page']) { case "Introduction": include ('introduction.xhtml'); break; case etc etc } include ('navigation.xhtml'); include ('footer.xhtml'); Is this a good way of stucturing my site? I have tested it, and it works but this current method has caused some new issues. 1: I am not sure how to change to the keywords and description in the header.xhtml 2: My CSS relies on an id added to the <body> element. Again, I am not sure how to change this depending on the page. Both of those items are in the header.xhtml file and are included [and displayed] before the content is chosen, so it is too late to change any of the details. I know this section is just for Design and Layout but I thought I should highlight my current issues. Is there a better way of dealing with this? All help is greatly appreciated
×
×
  • 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.