Jump to content

lfernando

Members
  • Posts

    43
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

lfernando's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks. Yes, I only put the same ID on the thread for example, but it's actually being set by a variable. So there is no way to do this using regex? ie, find a pattern that does not contain a string, replace with something else?
  2. Hi there, I've been trying to get this to work but no dice, hope one of you can help me? I need to find all "<li>" tags that do not contain a certain string, and insert another string. For example, find "<li>" tags that do not contain "123" and replace them with "<li id="123">" // Pear, Watermelon and Tomato do not contain 123 <ul> <li id="123_1" title="" value="1">Banana</li> <li id="123_2" title="" value="1">Apple</li> <li>Pear</li> <li title="" value="1">Watermelon</li> <li id="456_2" title="" value="1">Tomato</li> </ul> <ul> <li id="123_1" title="" value="1">Banana</li> <li id="123_2" title="" value="1">Apple</li> <li id="123" >Pear</li> <li id="123" title="" value="1">Watermelon</li> <li id="123" title="" value="1">Tomato</li> </ul> Any help would be much appreciated! Thank you!
  3. Thank you for your help! Just curious, why avoid using regex on HTML? If it makes a dfference this HTML code is stored in a MYSQL database which im accessing via PHP.
  4. Looking for strings that start with <li and end with either value="pass">, value="fail"> or just >. I need to replace each of these strings with a different variable, and also the result must include whatever was in between the start and end of the string. I managed to do it, but I'm using three different preg_replace. Surely this can be done more efficiently in one single pre_replace. Any ideas? Thanks! $string=' <li id="5691_3" value="pass"> Some text here</li> <li id="5691_4" value="pass"> Some text here</li> <li id="5691_6"> Some text here</li> <li id="5691_7" value="fail"> Some text here</li> ' $varPass= "You passed! - "; $varFail = "You failed! - "; varBlank="Its blank! - "; $string= preg_replace('/<li ([^>]*) value="pass">/', '<br>Result for $1 ' . $varPass, $string) $string= preg_replace('/<li ([^>]*) value="fail">/', '<br>Result for $1 '.$varFail, $string) $string= preg_replace('/<li ([^>]*)>/', '<br>Result for $1 '.$varBlank, $string); $string=str_replace("</li>","",$string); // this results into... $string=' <br>Result for id="5691_3" - You passed! Some text here <br>Result for id="5691_4" - You passed! Some text here <br>Result for id="5691_6" - Its blank! Some text here <br>Result for id="5691_7" - You failed! Some text here '   
  5. I figured it out, it had nothing to do with PHP. It was all Ajax and JS. I have to have the JS scripts inside a function, and call that function after ajax load. Thanks anyways
  6. Either $_POST, $value or $_SESSION are not arrays, so the "foreach" expression is invalid. Try using if(is_array($value)) { foreach($value.. } Its always a good idea to check if the variable is an array before performing a foreach
  7. Hello, Im trying to use the script from this page : http://css-tricks.com/long-dropdowns-solution/ Its basically a dropdown navigation menu. The thing is, the dropdown is populated from an ajax load (http.responseText) so the items in the list load after the script, and they dont appear as dropdowns. Any idea how to run a script after ajax load? Thank you!!
  8. Thank you! Yes I know the code is messy.... My users update documents using a WYSIWYG editor (www.tinymce.com). Whenever a change is made, it's recorded in the history. For this I use Paul Butler's string diff algorithm (http://paulbutler.org/archives/a-simple-diff-algorithm-in-php/) For example, the document says "Hello are you there?" and the user changes it to "Hello who is there?". The history will say: "2012.10.40: Hello are you who is there?" For some reason whenever the string has a path to a file, or bullet points, or in some other scenarios, some strikethrough tag (<del>) and/or underline tag (<ins>) gets placed inside the break. I think it may be the combination of the algorithm and the WYSIWYG editor. I looked at them trying to figure out what whas happening but couldnt, figured it'd be easier just to "clean up" the history before publishing instead of investing any more time in these two pieces of code that otherwise work well for me. Thanks again for your code I will try it out !
  9. Hi there, I have a string with a bunch of line breaks tags (<br/>) that have stuff inside, for example: Hello<br <del>/>This is</del> <ins>How are you?<br </ins>/> I basically need to find <br XXX/> and replace it with <br/> XXX so my code should look like this Hello<br/> <del>This is</del> <ins>How are you?</ins><br/> I tried using a find and replace array but I know this would be so much easier with regex! Little help!? Thank you!
  10. Also, sometimes I may have to select by two rows (ie, select all elements where "owner=nancy" AND "task=misc")
  11. Hi. Thank you for your reply. The thing is that sometimes i need to pull them by owner, sometimes by task, or other rows. Any other suggestions?
  12. Hi there, Does anyone know how to select from a mutlidimensional array, and put the results in a new array? I figured it out but it takes a long time. My array is huge (over 1000+ items) and this search is performed about 50 times before loading the page. My array is called $tasks and it looks like this $tasks=Array( [0]=>array([id]=>"12"; [owner]=>"nancy"; [task]=>"clean the house"); [1]=>array([id]=>"23"; [owner]=>"toby"; [task]=>"do homework"); [2]=>array([id]=>"43"; [owner]=>"dan"; [task]=>"take out trash"); [3]=>array([id]=>"32"; [owner]=>"nancy"; [task]=>"cook dinner"); ) I want to be able to select from $tasks where owner="nancy", so i end up with this $nancy_tasks=array( [0]=>array([id]=>"12"; [owner]=>"nancy"; [task]=>"clean the house"); [1]=>array([id]=>"32"; [owner]=>"nancy"; [task]=>"cook dinner") ) Thank you!!!
  13. So I've been trying to do this for days now and i'm at my witts end. I hope someone has an easier way!! I have a table with "tasks" and "subtasks", like this: task_id Title Owner parent_task_id 1 house chores ana 0 2 groceries ana 0 3 homework pete 0 4 vacuum adam 1 5 clean windows mike 1 6 vacum carpet adam 4 As you can see... - Tasks 4 and 5 are children of task 1. - Task 6 is a child of task 4, hence a grandchild of task 1. - Task 2 and 3 dont have any subtasks. - Tasks and subtasks dont always have the same owner So I need to display this as follows: * House Choures * vacum * vacum carpet * clean windows * Groceries * Homework So I can query the DB and put all tasks into an array ($tasks[]), then i build the following code: function build_tasks($tasks,$parent_id) { if(is_array($tasks)) { foreach($tasks as$task) { if($task['parent_id']==$parent_id) { echo "<ul> * ".$task['title']."</ul>"; } build_tasks($task['task_id'], ($table_width-2), $tasks, $link); } } } so to build the table I start with build_tasks($tasks, 0). That way it will start building parents and subtasks, starting with the ones with parent task id =0. The problem is when i filter $tasks to only show tasks by "adam". Adam doesnt have any taskas with parent_task_id=0, because all his tasks are under someone else's, so they never show up. Please, please, PLEASE help!
  14. Hi all, I really hope someone out there can help me out! I have a string with hundreds of list items and they all have a unique id, they look like this: <LI id="1234_tab2_[234]"> apples <LI id="1234_tab2_[45]"> sun <LI id="1234_tab2_[95]"> sky <LI id="1234_tab2_[26]"> grass I need to find each id and look up the value in a SQL database, which look like this list_item_id list_item_value 1234_tab2_[234] red 1234_tab2_[45] yellow 1234_tab2_[95] blue 1234_tab2_[26] green Then i have to replace each list item with the value pulled up from the database, like this: I managed to do this using a series of for loops but it takes a long time to load the pages with over 300 list items The reason for this is that I dont know much about regex so i'm just using strpos and substr. Please help!! Thank you!
  15. horray! that works perfectly!! thank you so much
×
×
  • 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.