Adding somthing before words

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Adding somthing before words

Post by nickman013 »

Hello, I have over 1000 proxy IP's in an array, I want to add the word "deny from" before each ip, and echo it out so I have the full list of ips with deny from before it.

For example

323.232.12.32:3233
239.21.24.5:8080
67.3.25.66:90

i want to replace to

deny from 323.232.12.32:3233
deny from 239.21.24.5:8080
deny from 67.3.25.66:90


Is it possible to do this??

Thanks!!!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Use foreach to iterate over the elements, and echo a concatenation of "deny from" and the array element.
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Post by jimthunderbird »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php
  $proxy_ips = array(
    '323.232.12.32:3233',
    '239.21.24.5:8080',
    '67.3.25.66:90'
  );
  
  for($k=0;$k<count($proxy_ips);$k++){
    $proxy_ips[$k] = "deny from ".$proxy_ips[$k];
  }
  
  foreach($proxy_ips as $ip){
    print $ip."<br/>";
  }
  
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

thanks alot.
it made my life a zillion times easier
Post Reply