TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-21-2011, 07:10 AM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application Put in seperate $var content whats in between *&&*

Good day to you all,
I'm looking for a way to retrieve the text in between *& &* and put it's content into a $var. for each occurrence with in a string.

$occu[0] = "dsfsdf";
$occu[1] = "10";
$occu[2] = "10sct";

Is there a way to do this ?


I know how to do it but not recusively.


PHP Code:

function get_string_between($string$start$end){
    
$string " ".$string;
    
$ini strpos($string,$start);
    if (
$ini == 0) return "";
    
$ini += strlen($start);
    
$len strpos($string,$end,$ini) - $ini;
    return 
substr($string,$ini,$len);
}

$parsed get_string_between($tache"*&""&*");
$tache str_replace("*&","<div class=\"progress-containers\"><div style=\"width:",$tache);
$tache str_replace("&*","%\">$parsed</div></div>",$tache); 

Can somebody can give me a tips ?
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 02-21-2011, 10:59 PM   #2 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Default

Impressive, here is what I come back with from before your post.
how to implement it with a foreach loop.

Let says instead I use index 0 to give me the whole piece and I replace the whole string with anther with the "number" index 1 with the formated html. See code

PHP Code:

preg_match_all
('/\*&([a-z0-9]+)&\*/i',$tache,$outPREG_SET_ORDER);
echo 
$out[0][0] . ", " $out[1][0] . ", " $out[2][0] . ", " $out[3][0] . ", " $out[4][0] . "\n";
$i 0;
foreach (
$out[$i][0] as &$value) {
$value str_replace("*&","<div class=\"progress-containers\"><div style=\"width:",$value);
$value str_replace("&*","%\">$value[$i][1]</div></div>",$value);
    
$i++;

__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 03-01-2011, 12:49 AM   #3 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

Your loop can be confusing. It isn't wrong but can be hard to understand what is going on since you are pretty much using it like a while loop.

PHP Code:
$i 0;
$total sizeof($out);
while(
$i $total) {
    
$value $out[$i][0];

    
$value str_replace("*&","<div class=\"progress-containers\"><div style=\"width:",$value);
    
$value str_replace("&*","%\">$value[$i][1]</div></div>",$value);
    
$i++;

PHP Code:
for($i 0$total sizeof($out); $i $total$i++) {
    
$value $out[$i][0];

    
$value str_replace("*&","<div class=\"progress-containers\"><div style=\"width:",$value);
    
$value str_replace("&*","%\">$value[$i][1]</div></div>",$value);

Here is how you would use a foreach loop.

PHP Code:
foreach($out as $val) {
    
$value $val[0];

    
$value str_replace("*&","<div class=\"progress-containers\"><div style=\"width:",$value);
    
$value str_replace("&*","%\">$value[$i][1]</div></div>",$value);

I didn't update variables in the HTML within the loop so those may be incorrect.
__________________
Eric
wGEric is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Crop Content CΛSTΞX General 3 01-14-2010 07:38 PM
how to search the content of txt file meshi Absolute Beginners 11 11-01-2007 04:43 PM


All times are GMT. The time now is 05:13 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design