We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,731 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

PHP Search word

in the string XX is always changed and string can be longer or shorter and it can be without searched word, where XX is a number example:

1 kom. nije naručeno, obično dolazi za 5 dana., slični: sony-6am6ptb1a (0 kom.), sony-s006pb1a (-9 kom.)
So from that I need to output just: obično dolazi za 5 dana

So how can I chose just &find in any case?

my example that does not work:

foreach(int intIndex = 1; intIndex <= 31; intIndex++)
                        {
                            $find_kad = "obično dolazi za " . strval(intIndex) . " dana."
                            $find_kad_eng = "usually comes in " . strval(intIndex) . " days."

                            if (strpos($availability,$find_kad) !== false) 
                            {
                            //echo '$string contains $find';
                            $dostupno_je="Po narudžbi  ".$find_kad;
                            $dostupno_je_eng="On order it  ".$find_kad_eng;

                            mysql_query("UPDATE ps_stock_available SET out_of_stock=1 WHERE id_product = $ztoro_id_product");

                            mysql_query("UPDATE ps_product_lang SET available_later="$dostupno_je" WHERE id_product = $ztoro_id_product AND id_lang=1");

                            mysql_query("UPDATE ps_product_lang SET available_later="$dostupno_je_eng" WHERE id_product = $ztoro_id_product AND id_lang=6");


                            }
                            else{
                                // just write not avaiable
                                $find_kad= "NIJE DOSTUPNO":

                            }
                        }

I get error on frist line:

Parse error: syntax error, unexpected T_STRING in script.php on line 618
2
Contributors
3
Replies
3 Hours
Discussion Span
4 Months Ago
Last Updated
4
Views
Question
Answered
mehnihma
Posting Whiz in Training
234 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I'm slightly confused. You shouldn't store the complete string in the field, just the num_of_days. Let php build the phrase once a language has been chosen by the user.

e.g.

if($lang == 'en'){
    echo ".en." . $num_of_days . ".en.";
}else{
    echo ".cy." . $num_of_days . ".cy.";
}

I wouldn't do this for every instance of language string though. Using string arrays in a language file would be a better option.

diafol
Keep Smiling
Moderator
10,634 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57

There is no user input, this is to update database

mehnihma
Posting Whiz in Training
234 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Regardless, I'm not sure if this is the best way to store language strings. You're mixing the value (say '5') with the associated language string. THis may make the string unwieldy and difficult to update.

For each product, in the products table, I'd have the value in its own field, e.g. 'available_in' storing just integers

If you're storing language strings in the ps_product_lang table, it would benefit from have a generic statement that could be used for all products using a placeholder, e.g.

translations

translated_id (int/PK)
langstring_id (int/FK)
lang_id (tinyint/FK)
content (varchar or text)

1
5
4
Bydd y cynnyrch hwn ar gael ymhen %d diwrnod.

This would be related to a couple of tables:

langstrings

langstring_id (int/PK)
linkcode (varchar[30])
original (varchar or text)

5
PRODUCT_AVAILABLE_IN
This will be available in %d days.

langs

lang_id (tinyint/PK)
lang_code (varchar [10])
lang_encoding (varchar [10])
default_lang_name (varchar [15])
native_lang_name (varchar [15])

4
cy_gb
utf8
Welsh
Cymraeg

Using sprintf(), you can substitute the placeholder for a real value. This can be done easily enough with a join query and some php formatting.

I apologise if I went off track and didn't actually anser your question or if I misunderstood what you're trying to do. It's just that your data structure looks awkward. Feel free to ignore this post.

diafol
Keep Smiling
Moderator
10,634 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57
Question Answered as of 4 Months Ago by diafol

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0638 seconds using 2.67MB