SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 1st, 2004, 06:43 PM
velocityX velocityX is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 72 velocityX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 36 sec
Reputation Power: 6
Send a message via AIM to velocityX
Grabbing a string in between two strings

Can somone tell me how or write me a function that will grab a string in between two strings?

Reply With Quote
  #2  
Old July 2nd, 2004, 05:36 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
What exactly do you want? Could you give an example please?

-KM-

Reply With Quote
  #3  
Old July 2nd, 2004, 09:46 AM
velocityX velocityX is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 72 velocityX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 36 sec
Reputation Power: 6
Send a message via AIM to velocityX
For example, im the .tmpl file the content is:

[forum_listcat]
<table>
{content}
</table>
[/forum_listcat]

[forum_listtopics]
<table>
{content}
</table>
[/forum_listtopics]

I need the example to grab the string in between the brackets,

[forum_listcat]
[/forum_listcat]

That part will only return

<table>
{content}
</table>

Reply With Quote
  #4  
Old July 2nd, 2004, 11:43 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
Ok here are some thoughts about how I would go about this -

1) You could use an xml file format instead, then one of the many high quality xml parsing tools available to do this rather than writing your own.

2) Create yourself a function that accepts the open and close tags and finds the occurances of them using strpos and then substr to get whats in between.

3) Some kind of clever regex which I'm sure is applicable here but personally I hate them and generally refuse to acknowledge they exist .

Hope one of these is of some use,

-KM-

Reply With Quote
  #5  
Old July 2nd, 2004, 02:50 PM
velocityX velocityX is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 72 velocityX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 36 sec
Reputation Power: 6
Send a message via AIM to velocityX
Thx, I have successfully made an working function!

If anyone wants the code just ask for it here

Reply With Quote
  #6  
Old July 2nd, 2004, 08:45 PM
velocityX velocityX is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 72 velocityX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 36 sec
Reputation Power: 6
Send a message via AIM to velocityX
Wait.....Nevermind. The new function I made doesn't work correctly. Here's the code:

PHP Code:
function exo_skin($find)
        {

        include 
"exoConfigs.php";

                if (!
file_exists("".$tmplpath."".$skinfile.".tmpl")){
                        
$skin="Server Error: Skin file doesn't exist.";
                }
                else
                {

                        if (!
is_readable("".$tmplpath."".$skinfile.".tmpl")){
                                
$skin="Server Error: Skin file is not readable.";
                        }
                        else
                        {

                        
$handle fopen("".$tmplpath."".$skinfile.".tmpl""r");
                        
$output fread($handlefilesize("".$tmplpath."".$skinfile.".tmpl"));
                        
fclose($handle);

                if (
substr_count($output,"[".$find."]")=="0" || substr_count($output,"[/".$find."]")=="0"){
                    
$skin="Cannot find skin field specified.";
                }
                else
                {

                    
$first=0;
                    
$second=0;

                    
$first=strpos($output"[".$find."]");
                    
$second=strpos($output"[/".$find."]");
                    
$skin=substr($output$first$second);
                    
$skin=str_replace("[".$find."]","",$skin);
                    
$skin=str_replace("[/".$find."]","",$skin);
                    
//$skin = preg_replace("/\[".$find."\](.*)\[\/".$find."\]/Uis","$1", $skin);
                
}
                        }
                }

        return 
$skin;

        } 


When you call this function more than once, it messes up.

I used this:

PHP Code:
echo "".exo_skin("nocat")."<br>";
echo 
"".exo_skin("categories")."<br>";
echo 
"".exo_skin("listcattopics")."<br>";
echo 
"".exo_skin("notopiccat")."<br>"


with the content in skin.tmpl:
PHP Code:
[nocat]
{
exo_error}
[/
nocat]

[
categories]
<
b>{exo_topic}</b><br>
[/
categories]
[
listcattopics]
{
exo_topic}<br>
{
exo_desc}<br>
{
exo_topicsTopics - {exo_repliesReplies Last Post: {exo_lastpost}<br>
<
br>[/listcattopics]

[
notopiccat]
{
exo_error}<br>
[/
notopiccat


Here were the results:

PHP Code:
{exo_error
{
exo_topic}[listcattopics
{
exo_topic}
{
exo_desc}
{
exo_topicsTopics - {exo_repliesReplies Last Post: {exo_lastpost}

[
notopiccat] {exo_error}
[/
notopiccat]
{
exo_error


Does anyone know how to fix this problem?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Grabbing a string in between two strings


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway