SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adsense inside news content

    well
    i have news as a text field of mysql ..and is retrived from database using php..
    what i want to do is get that adsene inside the news content or news to wrap adsense

    how can i do that

    if i use substr..the news content is broken in many cases...
    like..
    ....he said

    adsense

    that ....

    so i can i warp or put adsense inside..
    i dont think its illegal to do that ..

  2. #2
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use a custom tag that you put where you want the adsense to appear, write that to the database along with your news text and then, for display, split the content with that custom tag as the parameter. That would give you an array with two elements; inbetween you'd put the adsense.

    Something like...
    PHP Code:
    <?php
    $s 
    "this is a string. <!-- more --> here's another string.";
    $bits split("<!-- more -->"$s);
    echo 
    $bits[0];
    include 
    "my_adsense_js_include.inc.php";
    echo 
    $bits[1];
    ?>

  3. #3
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for reply
    seems like too difficult question as no many replies

    any way that means i have to insert that custom made adsense code along with news content every time...

    and while breaking like this from where that <!-- more --> come in my news
    if i use function i think it will break things ...like words of sentences and even words itself
    like The president di
    adsense
    d the things....

    so ,by the way whats about breaking the news into two parts and while breaking search for .(foolstop) which indiate end of word...

    i have once such example but when i use it it does the work but 8/10 times it could not break and give 30 second exceeds....message...

    so any way
    by the way any designer way of doing it ...from designing as well i wasnot able to design to get that...

    any way thanks for reply

  4. #4
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The point is that you decide where to put the custom tag when you're typing your news in the textarea. I.e.:
    Code:
    This is the first part of my news item which I want to appear before the adsense block.
    <--my_custom_tag-->
    Now I proceed to type the portion of news that comes after the adsense block.
    Insert that into your database, and when retrieving it for display refer to the code in my previous post.

  5. #5
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyway thanks for yor answer but inserting adsense code every time doesnt sound pro to be frank ...
    and what about the news not published by us...

    ok i have an idea
    ok after i get the news
    PHP Code:
    $news=$row['news'];
    $total=strlen($news);
    then i may use substr to get may be 300 words then 
    news1
    =substr($news,0,300);
    then 
    news2
    =substr($news,301,$total)
    then 
    echo $news1
    adsense
    echo $news2 
    may be in diffrent <tr>

    but i see some problem here
    first thing it will chop off the words...
    if i use some custom made function not to break the word then ,what it normally does is it searchs for fool stop after 300 words (first . after 300 words,then only break it....)
    but that way the in news2( substr($str,301...) some part of first para will be repeated in that second para as well

    and second problem i dont think using function like strlen for whole string (news may be 10000 or even more words) is good option...or may give query exceeds 30 second limit.. message..
    or make query excecution slow

    i think it can be done being in this principle if some expert use their head..i hope it will be help ful for many
    can any expert ammend it a little considering those problems...

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Hi,
    Here is a function I came up with for inserting 2 images into a body of text. You can use the same principle for inserting your adsense.

    PHP Code:
        function array_insert($text$pos$image$image2=null$pos2=null) {
            
    $text split("[.]"$text);
            
            
                
    $array2 array_splice($text,$pos);
               if(
    $image !='<img src="images/" align="right" class="imagepad" />') {    
                
    $text[] = $image;
               }    
               
    $array array_merge($text,$array2);
              
              if(
    $image2 !='<img src="images/" align="left" class="imagepad" />') {
                
    $array3 array_splice($array,$pos2);
                   
    $array[] = $image2;
                   
    $array_double array_merge($array,$array3);
                   
                                  
               
    $return implode(" "$array_double);
            } else {
          
              
    $return implode(" "$array);
            }
            
               return 
    $return;
        } 
    Explanation:
    The function takes 3 required parameters:
    $text, $pos, $image
    (the other 2 are optional)

    $text = the body of text
    $pos = the position in paragraphs where you want the image or whatever
    $image = the image name

    usage:
    PHP Code:
    // eg $row['textbody'] from the database
    echo array_insert($row['textbody'], 5'myimage.jpg'); 
    would insert an image at the 5th paragraph break, obviously you could substitute the image for your adsense code

    Try it and see if it works for you!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


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
  •