1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Add <?php Echo $_get["q"]; ?> In My Php Code

Discussion in 'PHP' started by bondigor69, Jan 20, 2013.

  1. #1
    hey guys I want to add
    <?php echo $_GET["q"]; ?>
    PHP:
    instead of "news" in this PHP code
    <?php
    $rss = new DOMDocument();
    $rss->load('http://wordpress.org/news/feed/');
    ?>
    PHP:
    How can I do that
    Thank you for help
     
    bondigor69, Jan 20, 2013 IP
  2. subdivisions

    subdivisions Well-Known Member

    Messages:
    1,021
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    145
    #2
    $rss = new DOMDocument();
    $rss->load( $_GET['q'] );
    Code (markup):

    Unless you meant that literally, in which case:
    $rss = new DOMDocument();
    $rss->load( "http://wordpress.org/{$_GET['q']}/feed/" );
    Code (markup):
     
    subdivisions, Jan 20, 2013 IP
  3. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #3
    Its the second one, but it dosent work it gives me an error.
     
    bondigor69, Jan 20, 2013 IP
  4. subdivisions

    subdivisions Well-Known Member

    Messages:
    1,021
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    145
    #4
    What does the error say?
     
    subdivisions, Jan 20, 2013 IP
  5. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    $url = "http://wordpress.org/".$_GET['q']."/feed/";
    $rss = new DOMDocument();
    $rss->load($url ); 
    PHP:
     
    ogah, Jan 21, 2013 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    Are you sure you don't have
    $rss->load( 'http://wordpress.org/{$_GET['q']}/feed/' );
    Code (markup):
    or
    $rss->load( "http://wordpress.org/{$_GET["q"]}/feed/" );
    Code (markup):
    Neither of those will work.
     
    Rukbat, Jan 23, 2013 IP
  7. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #7
    is it a $_GET method? whatever format they're using maybe you're not catching it right?
    $_GET['q'] looks like something that works in AJAX script but I don't know about rss as I found it to be junky and clunky on site. If you want content you're better of having an A.I. script read articles and re-arrange the article by rule sets/filters. Then its unique content according to Google bots. Unless you make the A.I. program smart enoughto recognize words/and english language rules of verb/noun etc.
    I'm slowly making one of those you can see the test I ran for it to identify words/slangs/expressions here http://reneeweedon.com/AI/AI.php If you want it I can sell a copy of the program where I have it now in identifying words by separating them by white space and identifying them individually by noun/verb etc to derive meaning from a sentence by English language filter rules. You can modify it since its in PHP.
    Eventually I want it to make entire websites by asking it to do so. With long term goal of setting a billion AI loose on Internet to work as a billion/multi-billion computer teams 24-7. I'd also like it to learn every program language and be able to make me high-end programs to use/sell. AI making software. who knows what it can do long term since it reads English language now.
     
    ezprint2008, Jan 24, 2013 IP
  8. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #8

    
     
    <?php
    $var["q"]="none";
    echo "http://example.com/{$var["q"]}";
    ?>
    
    PHP:
     
    krakjoe, Jan 24, 2013 IP
  9. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #9
    Right. Only the first one is invalid.
     
    Rukbat, Jan 24, 2013 IP
  10. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #10
    No offense guys, but why the devil are you making a simple string addition so blasted complicated?!? Of course wasting double quote overhead then dicking around with curly brackets for christmas only knows what is some real head scratching nonsense.

    Oh wait, PHP developers...(and turdpress too!) gotta do EVERYTHING the hard way. Ogah had it 'right', though was wasting an extra variable on it...
    
    <?php
    $rss = new DOMDocument();
    $rss->load('http://wordpress.org/'.$_GET['q'].'feed/');
    ?>
    
    Code (markup):
    Should be all it needs...

    Though ogah may have been correct in that it probably should be in a var -- but that would be to sanitize, check for validity, etc, etc... since user input ($_GET, $_POST, etc) should ALWAYS be treated as if it's got gonorrhea.
     
    deathshadow, Jan 24, 2013 IP
  11. omgitsfletch

    omgitsfletch Well-Known Member

    Messages:
    1,222
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    145
    #11
    Honestly, it's all a matter of preference. I typically prefer to use the bracket method when my final string is joining a bunch of variables together, as in my opinion it makes it much more readable. NOTE: This only applies when the variables aren't array members, but rather short names.

    Yes, technically speaking, the method you posted is going to be slightly better performance wise; but realistically, the difference is going to be neglible unless you're doing hundreds/thousands of replacements. Different strokes for different folks.

    And yes, totally agree as to the sanitizing input aspect.
     
    omgitsfletch, Jan 28, 2013 IP