Jump to content

File get contacts between strings


Paulqvz

Recommended Posts

Good day all.

 

I am trying to get strings from txt file with a start and an end.

 

$file = "/var/www/html/sataxicrm/custom/include/language/lang.en_us.lists.php";
$content = file_get_contents($file);
$pos = strpos($content,"query_complaint_type_list");
$end = strpos($content,"status_0");
$string = substr($content,$pos,($end- $pos));
$array = nl2br($string);
//print $content;
echo "Database Value:Label Value <br>";
print $array;

The above code works well if you knowwhat your end string is, but in my case i do not know. i only know the start.
Below is an example of the text

As you can see i know it starts with account_type_dom but i do not know that it will end before industry_dom. so i need to stop before industry_dom. how do i do this?

 

Quote

account_type_dom
    @clear
    "": ""
    @orig Customer
    "Brand Owner ": "Brand Owner "
    Printing Company: Printing Company
    Installation Company: Installation Company
    Sales Person: Sales Person
    Zebra: Zebra
industry_dom
    @clear
    "": ""
    @orig Apparel
    @orig Banking
    @orig Biotechnology
    @orig Chemicals
    @orig Communications

 

Link to comment
Share on other sites

requinix. yes that is the layout of the file.

the php starts with 

<?php return; /* no output */>

then the rest is this.

query_complaint_type_list is a list name- same as account_type_dom,industry_dom

When the api calls "account_type_dom" it must only return 

  @clear
    "": ""
    @orig Customer
    "Brand Owner ": "Brand Owner "
    Printing Company: Printing Company
    Installation Company: Installation Company
    Sales Person: Sales Person
    Zebra: Zebra

When the api calls "industry_dom" it must only return 

 @clear
    "": ""
    @orig Apparel
    @orig Banking
    @orig Biotechnology
    @orig Chemicals
    @orig Communications

Edited by Paulqvz
Link to comment
Share on other sites

Is this file in some particular syntax? It looks like there's a format to it. Still don't know what "query_complaint_type_list" or "status_0" have to do with it, but the first step is probably to read the file into a PHP structure.

 

28 minutes ago, Paulqvz said:

the php starts with 

<?php return; /* no output */>

Why bother? Just make it a .txt file and be done with it. Don't clutter up the file with stuff that doesn't belong.

Link to comment
Share on other sites

stop worrying about "query_complaint_type_list" that was just me seeing if i can return data between 2 points - and it worked, but the problem is i wil always know the start point but never the end point, hend me trying to start at Example.

\nsales_stage_dom

$pos = strpos($content,"nsales_stage_dom");

and end befor \nsales_probability_dom

as that is where the dropdown info stops'

$end = strpos($content,"\n); and not $end = strpos($content,"\n\t);

 

\nsales_stage_dom
\n\t@clear
\n\t@orig Closed Lost
\n\t@orig Closed Won
\n\t@orig Id. Decision Makers
\n\t@orig Needs Analysis
\n\t@orig Negotiation\/Review
\n\t@orig Perception Analysis
\n\t@orig Proposal\/Price Quote
\n\t@orig Prospecting
\n\t@orig Qualification
\n\t@orig Value Proposition
\nsales_probability_dom
\n\t@clear
\n\t\"\": \"\"
\n\tClosed Won: \"100\"
\n\tId. Decision Makers: \"40\"
\n\tNeeds Analysis: \"25\"
\n\tNegotiation\/Review: \"80\"
\n\tPerception Analasis: \"50\"
\n\tProposal\/Price Quote: \"65\"
\n\tProspecting: \"10\"
\n\tQualification: \"20\"
\n\tValue Prospecting: \"30\"
\nactivity_dom
\n\t@clear
\n\t@orig Call
\n\t@orig Email
\n\t@orig Meeting
\n\t@orig Note
\n\t@orig Task
\nsalutation_dom
\n\t@clear
\n\t\"\": \"\"
\n\t@orig Dr.
\n\t@orig Mr.
\n\t@orig Mrs.
\n\t@orig Ms.
\n\t@orig Prof.
\nreminder_time_options
\n\t@clear
\n\t@orig 60
\n\t@orig 300
\n\t@orig 600
\n\t@orig 900
\n\t@orig 1800
\n\t@orig 3600
\n\t@orig 7200
\n\t10800: 3 hours prior
\n\t18000: 5 hours prior
\n\t@orig 86400
\ntask_status_dom

Link to comment
Share on other sites

9 minutes ago, requinix said:

Is this file in some particular syntax? It looks like there's a format to it. Still don't know what "query_complaint_type_list" or "status_0" have to do with it, but the first step is probably to read the file into a PHP structure.

 

Why bother? Just make it a .txt file and be done with it. Don't clutter up the file with stuff that doesn't belong.

I am already reading it, getting the output, now i need a way to start a my start point and then to end at last tab before ne line without a tab

Link to comment
Share on other sites

Easier to use file().

<?php
$data = file('paulq.txt', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);

$start = "sales_probability_dom";

$results = [];

$pos = array_search($start, $data);              // find start key

while ($data[++$pos][0]=="\t") {                 // check for  tab at start of line
    $results[] = trim($data[$pos]);
}

echo '<pre>', print_r($results, 1), '</pre>'; 
?>

giving

Array
(
    [0] => @clear
    [1] => \"\": \"\"
    [2] => Closed Won: \"100\"
    [3] => Id. Decision Makers: \"40\"
    [4] => Needs Analysis: \"25\"
    [5] => Negotiation\/Review: \"80\"
    [6] => Perception Analasis: \"50\"
    [7] => Proposal\/Price Quote: \"65\"
    [8] => Prospecting: \"10\"
    [9] => Qualification: \"20\"
    [10] => Value Prospecting: \"30\"
)

 

  • Great Answer 1
Link to comment
Share on other sites

1 hour ago, Barand said:

Easier to use file().


<?php
$data = file('paulq.txt', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);

$start = "sales_probability_dom";

$results = [];

$pos = array_search($start, $data);              // find start key

while ($data[++$pos][0]=="\t") {                 // check for  tab at start of line
    $results[] = trim($data[$pos]);
}

echo '<pre>', print_r($results, 1), '</pre>'; 
?>

giving


Array
(
    [0] => @clear
    [1] => \"\": \"\"
    [2] => Closed Won: \"100\"
    [3] => Id. Decision Makers: \"40\"
    [4] => Needs Analysis: \"25\"
    [5] => Negotiation\/Review: \"80\"
    [6] => Perception Analasis: \"50\"
    [7] => Proposal\/Price Quote: \"65\"
    [8] => Prospecting: \"10\"
    [9] => Qualification: \"20\"
    [10] => Value Prospecting: \"30\"
)

 

Exactly what i was looking for. Thank you thank you

Link to comment
Share on other sites

Quick question

 

how would i  get only   'ITC Profile Update

if i search for itc_profile_update.

then when category == 'itc_profile_update' = itc_profile_update then only show  'ITC Profile Update' from  {type_list_name = 'ITC Profile Update';  

 

if(category == 'itc_profile_update')            {type_list_name = 'ITC Profile Update';             type_list_name2 = 'itc_profile_update_qt';}

Link to comment
Share on other sites

Sorry

 

this is my cases.js file

 

the js looks like this

 

if(category == 'itc_profile_update')            {type_list_name = 'ITC Profile Update';             type_list_name2 = 'itc_profile_update_qt';}
if(category == 'vehicle_sales')                 {type_list_name = 'Vehicle Sales';                  type_list_name2 = 'Vehicle_Sales_qt';}
if(category == 'icu_query')                     {type_list_name = 'ICU Query';                      type_list_name2 = 'icu_query_qt';}
if(category == 'self_help_app')                 {type_list_name = 'Self Help App Query';            type_list_name2 = 'self_help_app_qt';}
if(category == 'general_non_finance')           {type_list_name = 'gen_none_fin';                   type_list_name2 = 'general_non_finance_qt';}
if(category == 'legal')                         {type_list_name = 'Legal';                          type_list_name2 = 'legal_qt';}
if(category =='insurance_documents')            {type_list_name = 'Insurance Documents';            type_list_name2 = 'insurance_documents_qt';}
if(category == 'insurance_general_queries')     {type_list_name = 'Insurance General Queries';      type_list_name2 = 'insurance_general_queries_qt';}
if(category == 'contact_details_update')        {type_list_name = 'contact_details_update';         type_list_name2 = 'contact_details_update_qt';}

 

so i want to do a search form - php where if a person enters "general_non_finance" it will only bring back "gen_none_fin" .

$complaint_type = 'general_non_finance';
$sub = "'if(category == ' ";
$file = "//var/www/html/sataxicrm/modules/Cases/cases.js";
$content = file_get_contents($file);
$pos = strpos($content,$sub.$complaint_type);
$end = strpos($content,";}");
$string = substr($content,$pos,($end- $pos));
$array = nl2br($string);
//print $content;
echo "Query complaint value:Sub value <br>";
print $array;

Hope this make more sense

Link to comment
Share on other sites

I understand now what you are trying to do. What I don't understand is why the **** you are using a js file to store data.

If you don't want to use a category table in a database, use something like an ini file (easy to maintain), for example

category.ini

[itc_profile_update]
1="ITC Profile Update" 
2="itc_profile_update_qt"

[vehicle_sales]
1="Vehicle Sales"
2="Vehicle_Sales_qt"

[general_non_finance]
1="gen_none_fin"
2="general_non_finance_qt"

[legal]
1="Legal"
2="legal_qt"  

Then in php it's...

$categories = parse_ini_file('category.ini', 1);

$complaint_type = 'general_non_finance';

echo $categories[$complaint_type][1];     // --> gen_none_fin

To use the data in js, use an ajax call which returns

json_encode($categories)

 

Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.