SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Get date strings, convert to hyperlinked string?

    I have a script which I'm using for a CMS of minor news tidbits. It uses fputs to print into a text file. What I would like it to do is take all date strings or phrases (i.e.- xx/xx/xxxx, xx-xx-xxxx, etc) which are typed-out in the textbox and convert them to a predefined hyperlink.

    Is this possible? I was thinking that some sort of fgets if statement might be used to retrieve the phrase from within news1.txt and somehow convert it to a hyperlink which would be derived from some variable...? Thanks for any help.

    Code:
    <?php
    }
    }
    if ($action=="auth") {
    $f=$HTTP_POST_VARS['f'];
    $f=stripslashes($f);
    $fp = fopen("news1.txt", "w");
    fputs($fp, $f);
    fclose($fp);
    php?>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Do you want to transform the text before you store it, ie as a link in text1.txt, extract it and store it seperately so 01/01/2007 is from text1.txt or do you want to extract the date only when you parse text1.txt ?

  3. #3
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure Cups. ...Good Q.
    Which (in your eyes) would be most sensible? If I could apply different URL's to each individual date phrase, then that would be great, but if it's easier to code for one single URL, then that's okay too.

    I guess transform it when the text is extracted from the file...

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I cant advise without understanding your reason for doing things this way.

    Where is the text string coming from?
    Why are you storing it as a file?

    If possible post a real world example, just change the text slightly so we dont know the real reason you are doing it.

  5. #5
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    I cant advise without understanding your reason for doing things this way.

    Where is the text string coming from?
    Why are you storing it as a file?

    If possible post a real world example, just change the text slightly so we dont know the real reason you are doing it.
    The author of the site (webmaster) needs to post updates to the site. It's a very limitted amount of news, but from the control panel the author can type into a textbox what he/she needs to have on the website after clicking "Save".

    The news which was already on the website is loaded into this textbox when the author logs into the control panel, and from that point, can edit, delete, add and then save.

    The entire text is being drawn in from a single text file, and it is the file where these news tidbits are being saved. The reason I'm storing it as a single file and not a complete database is because I needed the text to be completely portable, and not to be dependant on a data base.

    By the way, I hope I haven't come across as someone who is out for anything malicous. I'm simply someone who has little programming experience as this is a program which I found on the i'net and am trying to customize it for my own devices (modified CMS usage).

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Right, so it might look like this:

    $f = "06/23/2006 Jackanory Jackanory, this is a story...";

    and you want to parse the data out and write the file as:

    06_23_2006.txt

    Is that what you mean?
    PHP Code:
    $file  "06/23/2006 Jackanory Jackanory, this is a story...";

    $t preg_match_all("#\d{2}/\d{2}/\d{4}#",  $file$matches);

    print_r($matches); 
    This extracts that date match ... gotta go now... does that give you a start?

  7. #7
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Right, so it might look like this:

    $f = "06/23/2006 Jackanory Jackanory, this is a story...";

    and you want to parse the data out and write the file as:

    06_23_2006.txt

    Is that what you mean?
    PHP Code:
    $file  "06/23/2006 Jackanory Jackanory, this is a story...";

    $t preg_match_all("#\d{2}/\d{2}/\d{4}#",  $file$matches);

    print_r($matches); 
    This extracts that date match ... gotta go now... does that give you a start?

    This is definitely a good start, I think. Ha.

    When you get a chance or when convenient for you, could you possibly elaborate on $file and "preg_match_all"? I looked the last up in the php manual and it sounded as if it's some sort of function which "siphons" whatever information you tell it to (in our case, the dates). Is this correct?
    Kudos to you for giving me some insight on this.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •