/    Sign up×
Community /Pin to ProfileBookmark

Can I place a while loop inside of an array?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 11.2006 — Well, an array is simply a variable for storing multiple data elements (either scalar values or other arrays), so to your literal question: no. I suspect, howver, that there's more to your question than that, so if you'd care to explain further what it is you want to do, maybe we can come up with a solution.
Copy linkTweet thisAlerts:
@pcthugNov 11.2006 — Not exactly a very good coding practice, but you could store the results (i.e. function callback) of a while loop:[code=php]
function myFunction($arg)
{
while($arg)
{
echo 'Hello, World!';
}
}

$myVariable = myFunction(1);

$myArray = array($myVariable);
[/code]
Copy linkTweet thisAlerts:
@HellgYNov 11.2006 — You could store the code of a dynamically created while loop in a variable, and then eval() it in order to execute the loop
Copy linkTweet thisAlerts:
@The_Little_GuyauthorNov 11.2006 — I was thinking something along these lines:
[code=php]<?php
function bb2html($strInput)
{
$arrBbcode = array
(
'/[B](.+?)[/B]/i',
'/[I](.+?)[/I]/i',
'/[U](.+?)[/U]/i',
'/[H1](.+?)[/H1]/i',
'/[H2](.+?)[/H2]/i',
'/[H3](.+?)[/H3]/i',
'/[H4](.+?)[/H4]/i',
'/[H5](.+?)[/H5]/i',
'/[H6](.+?)[/H6]/i',
'/(.+?)[/quote]/i',
'/[url=(.+?)=(.+?)](.+?)[/url]/i',
'/[FE]/i',
'/[/FE]/i',
'/[E=(.+?)]/i',
'/[N=(.+?)]/i',
'/[S=(.+?)]/i',
'/[SEN=(.+?)]/i',
'/[M=(.+?)=(.+?)]/i',
'/[IMG=(.+?)=NL]/i',
'/[IMG=(.+?)]/i',
'/[L1=(.+?)](.+?)[/L]/i',
'/[L2=(.+?)](.+?)[/L]/i',
'/[L3=(.+?)](.+?)[/L]/i',
'/[L4=(.+?)](.+?)[/L]/i',
'/[L5=(.+?)](.+?)[/L]/i',
);
$arrHtml = array
(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<h1>$1</h1>',
'<h2>$1</h2>',
'<h3>$1</h3>',
'<h4>$1</h4>',
'<h5>$1</h5>',
'<h6>$1</h6>',
'<blockquote>$1</blockquote>',
'<a class="$1" href="$2">$3</a>',
'<form action="user_email.php" method="post">',
'</form>',
'<input type="text" name="email" size="$1">',
'<input type="text" name="name" size="$1">',
'<input type="text" name="subject" size="$1">',
'<input type="submit" name="submit" value="$1">',
'<textarea cols="$2" rows="$1" name="message"></textarea>',
'<img src="user_images/user_thumbs/$1">',
while($row = mysql_fetch_array($sql)){
'<img src="user_images/user_thumbs/$1">',
}
'<a class="$1" href="user_index.php">$2</a>',
'<a class="$1" href="page2.php">$2</a>',
'<a class="$1" href="page3.php">$2</a>',
'<a class="$1" href="page4.php">$2</a>',
'<a class="$1" href="page5.php">$2</a>',
);
return preg_replace($arrBbcode, $arrHtml, $strInput);
}
?>[/code]


in reality If I don't have to do this, it probably would be awsome.

What I need to do is get the image and determine whether it is a link to a larger image or a link to a URL, so everytime they type in: [IMG=imagename.jpg] it will automatically pace the <a href="">around the image with the correct link.
×

Success!

Help @The_Little_Guy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...