SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow matching and using

    I have a database-drivin' website and I want to do the following.
    I want to check if in the $text there are occurences of <a href="java script:MenuParagraph(9,10);"> and use the numbers (they are PagID's) in a array.

    Why? Because Google doesn't recognize links when they are javascripts. So, I want to put them in an array and print them in a div (display:none) at the bottom of the page as normal <a href="">'s.

    In the case above this would give:
    <div style="display:none;">
    <a href="http://my.website.com/index.php?pageid=9">linkname</a>
    <a href="http://my.website.com/index.php?pageid=10">linkname</a>
    </div>

    Now, the problem is: How can I get those numbers and put them in an array?
    Any help is appreciated!

    Jazz

    PS: I've messed around with the ereg things, but I can't figure those things out. Putting stuff in an array and exploding / foreaching them isn't the problem. Just to find the occurences of the javascript and stripping it down to the numbers and using those numbers.
    Last edited by jazztie; May 27, 2003 at 09:07.

  2. #2
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you give an example of exactly what you need to match?
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  3. #3
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An example piece of text would be: (as a variable $text)
    These services are organised on behalf of Leiden University, colleges of higher education, as well as secondary schools. ICLON conducts its own educational research program, which focuses on the knowledge base of teaching.

    Where the link is: <a href="java script:MenuParagraph(12,70);">educational research program</a>

    The first number (12) is a PageID for the chapter, the second number (70) is the PageID for the paragraph. I would like to get both. So, in an array it would give:
    $array[0] = 12.
    $array[1] = 70.

    Now, I already have the code to read out the array and put convert them into normal <a href="">'s.
    PHP Code:
    foreach($array AS $googleID){
    $splita explode(",",$googleID); 
    print 
    "<a href="http://www.mywebsite.nl/frames/content.php?pageid=" . $splita[0] . "">" . $splita[1] . "</a><br>";

    // the explode is used because I also stored the titles of the pages in them. 
    So, what I need exactly is for the code to match every java script:MenuParagraph(*,*); where it should filter out the *, being numbers varying from 1 - 9999. (not a fixed length, as my page has several hundreds / thousands pages)

    Thanx
    Jazz

    PS: this editor parses it differently. There shouldn't be a space between java and script. (obviously)
    PPS: by the way, getting them into an array isn't the problem either. What I use is:
    $array[$arraycounter] = $PageID . ',' . $Title;
    $arraycounter = $arraycounter + 1;

  4. #4
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $text '<a href="javascript:MenuParagraph(1,2);">Educational Research 1</a>
    <a href="javascript:MenuParagraph(9,33);">Educational Research 2</a>
    <a href="javascript:MenuParagraph(11,1);">Educational Research 3</a>
    <a href="javascript:MenuParagraph(23,88);">Educational Research 4</a>
    <a href="javascript:MenuParagraph(44,999);">Educational Research 5</a>
    <a href="javascript:MenuParagraph(88,12);">Educational Research 6</a>'
    ;
    preg_match_all('/<a[^>]*?href=""("|\')javascript:menuparagraph\(([\d]+?),([\d]+?)\);?\1[^>]*>(.*?)<\/a>/si'$text$matchPREG_SET_ORDER);
    print_r($match); 
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  5. #5
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx for the code! That did work. (however, i did remove the stuff after the ;.
    PHP Code:
    preg_match_all('/MenuParagraph\(([\d]+?),([\d]+?)\);/si'$Text$match1PREG_SET_ORDER); 
    BTW: how did you get the entire number?
    I tried the following:
    PHP Code:
    preg_match_all('/linkid\=([\d]+?)/si'$Tekst$match1PREG_SET_ORDER); 
    But that just gave me the first number after linkid (if text contains: www.blabla.nl/?linkid=293)

    I don't understand what the difference is between your code and my code. Yours does parse the whole number... but mine doesn't (in the last example that is)...

    Jazz


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
  •